0
votes

I am trying to use rabbitmq topic exchange. In rabbitmq web management i created a queue called queue1 with this details :

enter image description here

After creating queue i used default exchange amq.topic and i binded queue1 to this exchange with anonymous.info routing key:

enter image description here

After push some message to this queue1 :

enter image description here

Now i want to consume these messages so in order to i wrote this script:

var amqp = require('amqplib/callback_api');
amqp.connect(uri, (error0, connection) => {
    if (error0) {
        throw error0;
    }
    connection.createChannel((error1, channel) => {
        if (error1) {
            throw error1;
        }
        var exchange = 'amq.topic';

        channel.assertExchange(exchange, 'topic', {
            durable: true
        });

        channel.assertQueue('queue1', { exclusive: true, durable: true }, (error2, q) => {
            if (error2) {
                throw error2;
            }
            console.log(' [*] Waiting for logs. To exit press CTRL+C');
            var key = 'anonymous.info';

            channel.bindQueue(q.queue, exchange, key);
            channel.consume(q.queue, function (msg) {
                console.log(" [x] %s:'%s'", msg.fields.routingKey, msg.content.toString());
            }, {
                noAck: true
            });
        });
    });
});

But i got this error :

Error: Operation failed: QueueDeclare; 405 (RESOURCE-LOCKED) with message "RESOURCE_LOCKED - cannot obtain exclusive access to locked queue 'queue1' in vhost '/'. It could be originally declared on another connection or the exclusive property value does not match that of the original declaration."

So i change channel.assertQueue() method to this, means i removed queue name:

channel.assertQueue('', { exclusive: true, durable: true }, (error2, q) => {
    if (error2) {
        throw error2;
    }

Now i did not get those error but i did not any result. I have 101 messages in queue1?

In channel.assertQueue callback the result of q is :

Object {queue: "amq.gen-Z7PhA8xKdA7v0H_33alxDA", messageCount: 0, consumerCount: 0}

but i do not have this queue name amq.gen-Z7PhA8xKdA7v0H_33alxDA.

It is Temporary queues but i have a queue and i want to read from my queue.

1
Maybe it's a bit late for my answer, but the answer is that you should change the type of queue from 'exclusive: true' to 'exclusive: false'. Then you will be able to consume your messages. RegardsR13mus

1 Answers

1
votes

from the snapshot your "queue1" is durable, non-exclusvie; and your code try with a queue durable, exclusive