简体   繁体   中英

Trying to connect to a rabbit mq

I'm new to message queue's and i'm trying to connect to a rabbit mq instance that was setup for me using https://github.com/squaremo/amqp.node and i'm definitely on the struggle bus.

I took the example from here and i'm trying to plug my values in and I'm getting no where.

Here's the info I was given:

Server: myserver
Queue: uinotification
username: myuser
password: mypass

Here's my attempt at using this example but I think instead of having to assert the queue i need to bind to it (i think).

Here's the docs for bindQueue: http://www.squaremobius.net/amqp.node/doc/channel_api.html#toc_39

I think i'm confused by the exchange piece.

amqp.connect('amqp://myuser:mypass@myserver').then(function(conn) {
    process.once('SIGINT', function() { conn.close(); });
    return conn.createChannel().then(function(ch) {
        var ok = ch.assertExchange('logs', 'fanout', {durable: false});
        ok = ok.then(function() {
            //return ch.assertQueue('', {exclusive: true});
            return ch.bindQueue('uinotification', 'logs', '');
        });
        /*ok = ok.then(function(qok) {
            console.log('qok = ');
            console.log(qok);
            return ch.bindQueue(qok.queue, 'logs', '').then(function() {
                return qok.queue;
            });
        });*/
        ok = ok.then(function(queue) {
            console.log('queue = ');
            console.log(queue);
            return ch.consume(queue, logMessage, {noAck: true});
        });
        return ok.then(function() {
            console.log(' [*] Waiting for logs. To exit press CTRL+C');
        });

        function logMessage(msg) {
            console.log(" [x] '%s'", msg.content.toString());
        }
    }).catch(function(err) {
        console.error('err = '+err);
    });
}).then(null, console.warn).catch(function(err) {
    console.error('connect err = '+err);
});

Here's the error I get with the above code:

Channel closed by server: 404 (NOT-FOUND) with message "NOT_FOUND - no previously declared queue"

A queue has to exist before you can bind to it, thus asserting it into existence first is actually what you need to do before binding to it.

Note that the settings for the queue have to be exactly the same as the ones the queue has been first created with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM