Archive for August, 2011

fun with nodejs and rabbitmq

The long awaited server side javascript revolutions is alive and well!

Here is a quickstart for funning around with nodejs and rabbitmq

The copy-pasta is from my retro machine at the house running ubuntu 10 (Maverick), but there’s little ubuntu specific stuff…

install nodejs

 % git clone https://github.com/joyent/node.git
 % cd node
 % sudo apt-get install g++ libssl-dev
 % ./configure && make && sudo make install
 % echo 'console.log( "go node!" )'  | node

install npm

As per the website, you can run the install script from curl.

Oddly enuff, to avoid running it as root, buddy suggests making your user own all of /usr/local.

Instead, I thought I’d add an npm user and setuid the npm stuff:

 % sudo adduser --gid 0 npm
 % sudo chmod g+w /usr/local/lib 
 % sudo chmod g+w /usr/local/share/man 
 % sudo chmod g+w /usr/local/bin 
 % sudo chmod g+w /usr/local/man/man1
 % sudo su npm
 % cd /tmp
 % git clone https://github.com/isaacs/npm.git
 % cd npm
 % ./configure
 % make && make install 
I tried setting 4755 on /usr/local/lib/node_modules/npm/bin/npm.js, but it complains when I tried to install some stuff..

Just have to use the npm user to install node-amqp:

 % sudo su npm -c "npm install -g amqp"
 % cd 
 % ln -s /usr/local/lib/node_modules

install rabbitmq

The out of the box rabbit for ubu10 was ancient bullshit!

The rabbitmq guys have some tips… basically:

 % echo deb http://www.rabbitmq.com/debian/ testing main | sudo tee -a /etc/apt/sources.list
 % wget http://www.rabbitmq.com/rabbitmq-signing-key-public.asc
 % sudo apt-key add rabbitmq-signing-key-public.asc
 % sudo apt-get update
 % sudo apt-get install rabbitmq-server

It gets cranked up at install and there is a handy init script:

 % sudo /etc/init.d/rabbitmq-server status

a simple demo

So… this code runs fine on my mac, but is weirdly busted on my olde ubuntu box:

clear ; ./amqp-dee-dum.js
connected
ready
got the exchange
[hilarity ensues: try it out!]

I had to create new exchange named ‘tmp’, it wouldn’t let me use ‘amq.direct’ for some reason…

Anyhooo…

I think the code is pretty ez to follow if sorta copy-pasta heavy.

I hope to do a refactored version at some point…

what happened with the old rabbit

connected
ouch: Oversized frame 1342243080
cya!
FATAL ERROR: v8::Object::SetIndexedPropertiesToExternalArrayData() length exceeds max acceptable value

Using the non-crusty version everything worked fine.

Comments (2)