Deepanshu Sukhija
Deepanshu Sukhija

Reputation: 63

Connecting RabbitMq to an TCP/IP server

I am using RabbitMq as a Queueing Mechanism for my message handling. So far, all the queues are generating fine on the localhost but when I moved on to the server. It started showing

    connection timeout error

This is my connecion string.

    var amqp = require('amqp');
    var connection = amqp.createConnection({
        url: 'amqp://username:passwprd@server-IP:5672/'
      })
    connection.on('error',(err)=>{
        console.log(err);
      });
    var options = { autoDelete:false,
            durable:false,
            expiration:'20000',
     };
    connection.on('ready',()=>{
        connection.queue('queueName',options,(queue)=>{
            queue.bind('#');
            queue.subscribe({ack:true},message =>{
                console.log(message);
           });
       });
      });

Can anyone tell me what i am doing wrong here

Upvotes: 1

Views: 1421

Answers (2)

Nikhil
Nikhil

Reputation: 374

Actually I get what you are asking

Just type this code

     var connection = amqp.createConnection({
    url: 'amqp://localhost'
  })

on your server side code and the project will run fine as it is running on my server.

You don't need to specify the username and password or your server-ip.

Upvotes: 0

Mr. Ratnadeep
Mr. Ratnadeep

Reputation: 621

I have launched the Ubuntu EC2 instance and using putty utility I have installed rabbitq on the same. To know the status of rabbitmq service, you can type service rabbitmq-server status
enter image description here You can refer documentation from Rabbitmq node Rabbitmq I have tried with below code on aws instance and its working

var amqp = require('amqplib/callback_api');
amqp.connect('amqp://localhost', function(err, conn) {
    console.log(conn);
});

Output enter image description here

Upvotes: 1

Related Questions