Rene Wooller
Rene Wooller

Reputation: 1147

either 'when-js' or basic amqplib rabbitmq nodejs tutorial not working

I have the latest version of nodejs (0.10.21, amqplib (0.1.0)(https://github.com/squaremo/amqp.node.git) and rabbitmq (3.2.0).

  1. start rabbitmq-server
  2. go to amqp.node/examples/tutorials and run ./send.js after installing npm packages.

it reports: [x] Sent 'Hello World!'

From the rabbitmq web console, I can see it creates the connection, it creates the queue 'hello'. However it doesn't actually publish any message to the queue.

None of the other tutorials work for me except for the RPC client/server - they will create exchanges, queues and channels, but not publish messages.

One of my friends has it running fine using all the same versions except for OS X 10.6 rather than 10.8.

I've stepped through the amqplib code using node inspector and can't see any obvious errors. It did look like the message frame wasn't being created, but at that level I have no real idea what is going on at the moment.

When I publish messages via the web console or with Bunny + Ruby, it creates a queue AND publishes a message as expected, so it must be some problem with node, amqp and/or OS X 10.8 rather than rabbitmq.

The rabbitmq logs (tailing both logs) only mention the connection opening and then closing very quickly afterwards, but doesn't report any errors:

=INFO REPORT==== 27-Oct-2013::20:46:16 === accepting AMQP connection <0.731.0> (127.0.0.1:56927 -> 127.0.0.1:5672)

=INFO REPORT==== 27-Oct-2013::20:46:16 === closing AMQP connection <0.731.0> (127.0.0.1:56927 -> 127.0.0.1:5672)

I've sniffed the packets being sent from amqp node to rabbitmq. This from amqp.node running the first example 'send.js' in examples/tutorials:

http://www.limorph.com/files/amqp_amqnode_send.txt

You can see how it opens the connection, creates the queue and closes the connection, but doesn't sent a message.

This one is from ruby/bunny - you can see how it opens the connection, creates the queue, and publishes the message.

http://www.limorph.com/files/amqp_bunny.txt

I've found that if I remove conn.close(), it manages to publish the message.

eg

})).ensure(function() {
    //          conn.close();
});;

Not really a solution, but it points to maybe the problem being in 'when' rather than amqplib ?

Any ideas or help greatly appreciated

Upvotes: 2

Views: 1066

Answers (2)

Rene Wooller
Rene Wooller

Reputation: 1147

this was because I had run 'npm install' instead of 'npm install amqplib' or 'npm install ../..' . This meant that I was running off version 2.5.1 of 'when', which has some kind of malfunctioning race condition that closes the connection prematurely. When running off version 2.1.1, which amqplib is locked to, it works fine. –

Upvotes: 0

Michael Bridgen
Michael Bridgen

Reputation: 266

The short answer is: Closing a connection abandons any operations that haven't been written to the socket.

It seems that more recent versions of when.js (e.g., v2.5.1) manage to invoke the ensure clause, closing the connection, before the message has been written.

What's odd, perhaps, is that it's so consistent -- I haven't seen it succeed with when.js 2.5.1 and I haven't seen it fail with when.js 2.1.1. In any case, the way to fix it is to synchronise on something after the publish; for example, closing the channel.

There's a bit more detail at https://github.com/squaremo/amqp.node/issues/28

Upvotes: 0

Related Questions