I am trying to use rabbitmq topic exchange
. In rabbitmq web management i created a queue called queue1 with this details :
After creating queue i used default exchange amq.topic
and i binded queue1 to this exchange with anonymous.info
routing key:
After push some message to this queue1 :
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.