views:

359

answers:

2

I want to build a live application that supports server-push (chat, feeds, live notification and collaboration etc).

I have looked into Node.js and found it quite interesting and appropriate for such things.

I have also looked into AMQP/RabbitMQ, but I don't get these quite.

My questions:

  • How does AMQP/RabbitMQ compare to Node.js?
  • Could Node.js replace these?
  • Which solution is better for server push web applications?
+6  A: 

Node.js is an environment for doing event-driven programming in JavaScript. It's certainly appropriate for programs that are I/O bound; e.g., shuffling data between HTTP clients (browsers) and backend systems.

RabbitMQ is a messaging broker and it implements AMQP, which is a messaging protocol. It's built with Erlang/OTP, which is an environment for doing highly concurrent programming.

You could replace RabbitMQ with Node.js in the sense that JavaScript is a general-purpose programming language; in principle you can always write something from scratch that has the particular features that you might need from RabbitMQ (work distribution, persistent queuing, ..). Node.js is even appropriate for many of these kinds of features (lots of I/O, not too much state).

It really makes more sense to compare Node.js with Erlang/OTP; and, since Erlang/OTP has been used in production systems for decades, inevitably this is something of a one-sided comparison. But you didn't ask about Erlang.

For your particular use, you have the by-now classic dilemma: write something from scratch, or adapt to your purpose something that already exists. Neither represents a ready-made solution, just a different trade-off.

Actually it's not quite so clear cut as that; you might choose to use Node.js to proxy your browser-borne connections (websockets?) through to RabbitMQ; that's the sort of thing Node.js is good at, and there's even an AMQP adapter for Node.js. Putting aside Node.js, RabbitMQ has plugins for things like pubsubhubbub and STOMP and JSON-RPC, one of which may be what you need.

(Disclosure: I work on RabbitMQ, and with Node.js)

Michael Bridgen
@Michael: Thanks for the reply. Your suggestion for the flow is like this: web browser <-> web server (node.js) <-> rabbitmq ?
never_had_a_name
@Michael, great comment. I also don't understand the use for RabbitMQ pretty well, maybe you could elaborate on the use of RabbitMQ and node.js?
donald
Yep, node.js acts as a protocol adapter, more or less. Perhaps spend a bit of time on a proof of concept, then you'll see what value you're getting out of each bit if any. node-amqp = http://github.com/ry/node-amqp; node-websockets = http://github.com/guille/node.websocket.js/, passim. I'm not sure what you want actually publishing messages on the server, but there are AMQP clients in many languages.
Michael Bridgen
@donald On using RabbitMQ and node.js together? There's lot of scenarios. The one above is really about using node.js as a protocol adapter or proxy, which I think it can do quite efficiently.
Michael Bridgen
(Ops, hit enter expecting a newline). Other scenarios: using node.js processes as workers, either replying to requests that are load-balanced by RabbitMQ; or, transforming messages (messing with XML) and passing them back to RabbitMQ for the next stage in a pipeline (putting the XML in a database).
Michael Bridgen
If anyone is still watching: there's examples of using node.js with websockets/xhr and AMQP at http://github.com/jamescarr/nodejs-amqp-example and (my own) at http://github.com/squaremo/rabbit.js
Michael Bridgen
+1  A: 

sounds like you want a message driven web app. node isn't about messages or messaging, it's just an asynchronous runtime that happens to be good at webapps. rabbitmq is a message exchange, so it's not going to talk to web clients directly or serve as a webapp. what you likely want is an asynchronous runtime to host a webapp, which is driven by a messaging platform.

see these solutions for crossing the gulf:

  1. http://github.com/JustinTulloss/zeromq.node
  2. http://github.com/ry/node-amqp
rektide