Wednesday 9 March 2011

RabbitMQ and Node.js Websockets experiment

I've been experimenting with Rabbitmq and Node.js support for Websockets.
The idea is just have a backend to generate random numbers (0-10) and plot the numbers in a realtime graph with websockets.
For that we going to use a Publish/Subscriber model with AMQP and RabbitMQ. The backend (aka Groovy Script) publish the numbers in a exchange. And the suscriber (aka Node.js with Socket io) get the messages from the queue and push the messages in the web browser.

Here Groovy Script
to put messages in the exchange "stockExchange". It generates 1 message per 300 miliseconds !!!!


Here the client code, that use smoothiecharts to render the graph with Websockets


And here Node JS code that suscribes to an AMQP and send each message to the browsers
socketexample.js

3 comments:

Anonymous said...

Hello, I just read your blog post, and used it as an reference. But each time I call socket.broadcast() I recieve an error that this method does not exist.. do you have any idea on how to fixs that?

alexcuesta said...

I am loving this experiment :)

Anonymous said...

Hi, where did you declare the "stockQueue" queue?