I have a node.js app to be running with rabbitmq and mysql.
After setting everything up, when I do npm start
I have given the user administrator tag and permissions as rabbitmqctl set_permissions RABBIT_USERNAME "." "." ".*"
It shows this error :
> node app.js
13:43
Started database log (Mon Jan 29 2018 13:43:42 GMT+0530 (IST))
13:43
Started mailer log (Mon Jan 29 2018 13:43:44 GMT+0530 (IST))
13:43
Started messaging log (Mon Jan 29 2018 13:43:44 GMT+0530 (IST))
13:43
Started messaging log (Mon Jan 29 2018 13:43:44 GMT+0530 (IST))
13:43
Started database log (Mon Jan 29 2018 13:43:44 GMT+0530 (IST))
13:43
Started socket log (Mon Jan 29 2018 13:43:44 GMT+0530 (IST))
13:43 messaging:3000 is listening..
13:43 DB connected (7)
13:43 DB connected (6)
13:43 Error:
Expected ConnectionOpenOk; got <ConnectionClose channel:0>
Error: Expected ConnectionOpenOk; got <ConnectionClose channel:0>
at /PATH/node_modules/amqplib/lib/connection.js:167:14
at /PATH/node_modules/amqplib/lib/connection.js:159:12
at Socket.recv (/PATH/node_modules/amqplib/lib/connection.js:497:12)
at Object.onceWrapper (events.js:255:19)
at Socket.emit (events.js:160:13)
at emitReadable_ (_stream_readable.js:520:10)
at emitReadable (_stream_readable.js:514:7)
at addChunk (_stream_readable.js:280:7)
at readableAddChunk (_stream_readable.js:256:11)
at Socket.Readable.push (_stream_readable.js:213:10)
at TCP.onread (net.js:599:20)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! messaging@ start: `node app.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the messaging@ start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/mishal23/.npm/_logs/2018-01-29T08_13_45_095Z-debug.log
Make sure the node is running using rabbitmq-diagnostics status. Verify config file is correctly placed and has correct syntax/structure. Inspect listeners using rabbitmq-diagnostics listeners or the listeners section in rabbitmq-diagnostics status. Inspect effective configuration using rabbitmq-diagnostics environment.
To connect to RabbitMQ from a different machine, you must open ports 5672 and 5672 for remote access.
In order for a client to interact with RabbitMQ it must first open a connection. This process involves a number of steps: Application configures the client library it uses to use a certain connection endpoint (e.g. hostname and port) The library resolves the hostname to one or more IP addresses.
There is no enough context on how this happened so I'm making a few assumptions:
amqplib
for the connection. (Not an assumption)So the first thing you need to do is to create a user if you haven't already.
sudo rabbitmqctl add_user admin password
sudo rabbitmqctl set_user_tags admin administrator
Run this command if you haven't enabled the Management Dashboard
sudo rabbitmq-plugins enable rabbitmq_management
By default, it runs on port 15672
. So don't forget to open that port. And you can access this dashboard using your.server.ip.address:15672
.
Now in this Management Dashboard, go to the Admin
tab and on the right side, you'll see a link to Virtual Hosts
.
There will be one virtual host named /
and user guest
(that you cannot access without localhost). Now create a new virtual host and check if it has the same user as you just created a few moments back (admin
in this case).
Use the string below to connect to the server instead of amqp://localhost
amqp://admin:[email protected]/vhost_name
You can use this example (or any other examples) for the rest of the things...
I hope this helps!
In my case, the issue was related to heartbeat. You have to pass the heartbeat as a parameter to your connection URL:
amqps://user:password@domain/vhost_name?heartbeat=30
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With