Reputation: 21
I am using amqplib to create amqp clients. it works fine when running on localhost, but when I change it to the server's IP address 192.168.1.44, I get an error that indicates the conn object is undefined.
this is the client's code
var amqp = require('amqplib/callback_api');
amqp.connect('amqp://guest:[email protected]:5672', function(err, conn) {
conn.createChannel(function(err, ch) {
var q = 'hello';
ch.assertQueue(q, {durable: false});
console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q);
ch.consume(q, function(msg) {
console.log(" [x] Received %s", msg.content.toString());
}, {noAck: true});
});
});
and this is the error message
/home/pi/Desktop/mqtt_example/receive.js:14
conn.createChannel(function(err, ch) {
^
TypeError: Cannot read property 'createChannel' of undefined
at /home/pi/Desktop/mqtt_example/receive.js:14:5
at /home/pi/Desktop/mqtt_example/node_modules/amqplib/callback_api.js:16:10
at /home/pi/Desktop/mqtt_example/node_modules/amqplib/lib/connect.js:164:12
at bail (/home/pi/Desktop/mqtt_example/node_modules/amqplib/lib/connection.js:176:5)
at afterStartOk (/home/pi/Desktop/mqtt_example/node_modules/amqplib/lib/connection.js:219:7)
at /home/pi/Desktop/mqtt_example/node_modules/amqplib/lib/connection.js:160:12
at Socket.recv (/home/pi/Desktop/mqtt_example/node_modules/amqplib/lib/connection.js:498:12)
at Object.onceWrapper (events.js:314:30)
at emitNone (events.js:105:13)
at Socket.emit (events.js:207:7)
at emitReadable_ (_stream_readable.js:502:10)
at emitReadable (_stream_readable.js:496:7)
at addChunk (_stream_readable.js:263:7)
at readableAddChunk (_stream_readable.js:239:11)
at Socket.Readable.push (_stream_readable.js:197:10)
at TCP.onread (net.js:588:20)
Upvotes: 0
Views: 4930
Reputation: 21
I fixed it by creating a new user on the rabbitmq broker. the guest user works only with localhost. for more details see https://stackoverflow.com/a/26820152/7236105.
Upvotes: 1