I have an instance of RabbitMQ (default configurations) running on Windows 8 environment. My node version is 5.1.0 and I am trying to establish a connection between them using amqp.node library in order to pass messages.
When I try the sample code:
var q = 'tasks';
function bail(err) {
console.error(err);
process.exit(1);
}
// Publisher
function publisher(conn) {
conn.createChannel(on_open);
function on_open(err, ch) {
if (err != null) bail(err);
ch.assertQueue(q);
ch.sendToQueue(q, new Buffer('something to do'));
}
}
// Consumer
function consumer(conn) {
var ok = conn.createChannel(on_open);
function on_open(err, ch) {
if (err != null) bail(err);
ch.assertQueue(q);
ch.consume(q, function(msg) {
if (msg !== null) {
console.log(msg.content.toString());
ch.ack(msg);
}
});
}
}
require('amqplib/callback_api')
.connect('amqp://guest:guest@localhost:5672', function(err, conn) {
if (err != null) bail(err);
consumer(conn);
publisher(conn);
});
I get it working okay.
But if I move this code, exactly how it is, into my project, I get this error:
ECCONRESET syscall: read.
My app runs with express.js and oauth2.0. Even if I put the code right before any other statements and modules' requires, it does not work.
I searched about this error and I found some problems related to load balance, but I am running it locally and the sample code works okay.
Another problem that I found could be related to TCP connection, I changed the handshake timout option inside RabbitMQ server's config file to 10000ms, but nothing changed.
I am using the same url with guest user: amqp://guest:guest@localhost:5672, which works on the sample code.
The log from RabbitMQ shows that a connection is done but a few seconds later, it states that the connection was closed unexpectedly:
=INFO REPORT==== 24-Nov-2015::18:09:52 ===
accepting AMQP connection <0.2644.0> (127.0.0.1:51866 -> 127.0.0.1:5672)
=ERROR REPORT==== 24-Nov-2015::18:10:12 ===
closing AMQP connection <0.2644.0> (127.0.0.1:51866 -> 127.0.0.1:5672):
{handshake_timeout,frame_header}
So my questions are: is there any conflict between amqp.node and other library that drops the connection with the server? How can I debug this?