amqp / rhea

A reactive messaging library based on the AMQP protocol
Apache License 2.0
280 stars 79 forks source link

Unable to Connect to AWS MQ broker using rhea npm module ? #124

Open mailmeankit opened 6 years ago

mailmeankit commented 6 years ago

Hi, I am trying to connect to AWS MQ broker and consume and publish the message to AWS Active MQ.

But I am unable to connect to Broker and not even consume and publish the message to the broker. I have written the code below, please have a look.

  var client = require('rhea');

  const queueName = 'queueName';
  client.connect({
      transport: 'tls',
      host: 'host_name',
      hostname: 'host_name',
      username: 'userName',
      password: 'password',
      port: port,
      reconnect_limit: 10
  });
  console.log("client is to be", client);

  client.on('connection_open', (context) => {
      console.log("connected");
      var receiver = context.connection.open_receiver({
          source: {
              address: `${queueName}/$management`
          },
          autoaccept: false,
          target: {
              address: 'receiver-link'
          }
      });
      receiver.once('receiver_open', (context) => {
          console.log('receiver is now open....', context);
      });

      receiver.once('message', (context) => {
          console.log('message received by receiver....');
          console.log("message is", context.message);
      });
  });

Can you please help me on this that what I am doing wrong, I am using rhea npm module in Nodejs?

Thanks

grs commented 6 years ago

Is there any error? Or it just never emits connection_open? You can get more information by setting env var DEBUG=rhea*.

mailmeankit commented 6 years ago

It never emits connection_open and I am still trying to debug this but still no success.

Do I need to add any more configurations or I am missing something to connect to AWS MQ via rhea module?

grs commented 6 years ago

DEBUG=rhea* will enable debug logging. I assume AMQP 1.0 is enabled for your AWS MQ instance?

erothmayer commented 6 years ago

I just completed the same exercise and got it working. If you attach on('connection_error', ...) to the connection (I attached it to the connection and container to be safe) you should get some more meaningful error messages.

mailmeankit commented 6 years ago

@erothmayer Sorry I didn't get it, can you please provide a code example to me or edit the above code for me, will be really helpful for me. I also tried with on('connection_error', ...) but still no success.

Thanks

mailmeankit commented 6 years ago

Hi,

Thanks for the details and yes I am able to connect to AWS MQ using rhea module.

Now, I am have come to another issue for my prod deployment, as I need to establish the connection with failover string as the deployment mode is active/standby. Below is the failover connection string format:

failover:(amqps://'your-host-name1':'port',amqps://'your-host-name2':'port')

I didn't find any method to implement the same using rhea module.

Can anyone please help me with this ?

Thanks

grs commented 6 years ago

Have a look at the reconnect example: https://github.com/amqp/rhea/blob/master/examples/reconnect/client.js#L38

You can specify a function to return the connection details and have this iterate over a list of host/port combinations.

mailmeankit commented 6 years ago

thanks, it's working, one more query I have is how to find the state of queue means is queue empty or how many messages exist in the queue?

grs commented 6 years ago

You would need to use some management api for the broker for that. If it supports management queries over amqp messages, you will need to get the broker specific schema for that.

mailmeankit commented 6 years ago

Ok I will look for that, but is there any way in rhea module through which I can get an iterator for messages, something like which tells is hasNext() exists or not?

grs commented 6 years ago

You can drain the credit, which tells you that either the broker sent you as many messages as you gave it credit for or had no further messages to give. See https://github.com/amqp/rhea/blob/master/examples/drain.js for a simple example of that.

yomgui666 commented 5 years ago

Hello mailmeankit.

We are striving connecting to an AWS MQ broker with the RHEA client, probably because of TLS as we got it working fine to a local ActiveMQ with TLS disabled.

Could you post the working code please ? (as the code posted initially doesn't work I understand).

Thanks.

Guillaume

grs commented 5 years ago

If tls is the issue, you can try rejectUnauthorised=true in the connect options. If it works with that, then it is likely an issue with the certificate/ca. If not, check the port in use.

thetechieskraft commented 5 years ago

I'm facing the same issue, could you pls share source code and steps whichever you have followed. Much appreciated for your help.

joanna-hugo commented 4 years ago

I am also having problems connecting to AWS MQ using the rhea module. Can anyone who has been successful please share some source code and the steps they followed? Thank you.