noodlefrenzy / node-amqp10

amqp10 is a promise-based, AMQP 1.0 compliant node.js client
MIT License
134 stars 56 forks source link

Connect does nothing #369

Open Kmasterrr opened 6 years ago

Kmasterrr commented 6 years ago

Hi there,

I am using Amazon MQ using the AMQP connection string and for some or other reason, the promises are not returning anything. No error or success..

I have copied the code from your examples, as well as played around with the policy and for some reason the application just waits..

Please assist. I just decommissioned my RabbitMQ server and now i need to sort the application via amazon MQ.

Code below:

var AMQPClient = require('amqp10').Client,
    Promise = require('bluebird'),
    Policy = require('amqp10').Policy;

var uri = 'my amazon amqp connection',
    msgId = Math.floor(Math.random() * 10000),
    client = new AMQPClient();

var client = new AMQPClient(Policy.merge({
    senderLinkPolicy: {
        callbackPolicy: Policy.Utils.SenderCallbackPolicies.OnSent
    }
}, Policy.DefaultPolicy));
client.connect(uri)
    .then(function() {
        return Promise.all([
            client.createReceiver('amq.topic'),
            client.createSender('amq.topic')
        ]);
    })
    .spread(function(receiver, sender) {
        receiver.on('errorReceived', function(err) { /* Check for errors */ });
        receiver.on('message', function(message) {
            console.log('Rx message: ', message.body);
        });

        return sender.send({ key: "Value" });
    })
    .error(function(err) {
        console.log("error: ", err);
    });
ps2goat commented 6 years ago

I had this same issue. 1) if the connector is anonymous, you need to specify the SASL mechanism: https://stackoverflow.com/a/43913433/2084315

2) if this is an authenticated user, I had to build the url with the creds in the url. (If there's a different way to do this, let me know.)

amqps://user:pw@url:5671

Be sure to run encodeURIComponent() your password before putting it in the url!

Also, if you have an AmazonMQ broker with failover, only one instance is available at a time. I've witnessed this switching back and forth unreliably as to which one is available. Try switching between your two urls (if you have them) if connect becomes unresponsive. I'm currently investigating whether this library supports setting up a failover.

jwgmeligmeyling commented 6 years ago

For those with the same issue under WildFly's embedded ActiveMQ message broker, see: https://issues.jboss.org/browse/WFLY-7823?focusedCommentId=13599179&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-13599179