我想在我的一个工人中在一定时间后收到一条消息。在发现所谓的死信交换后,我决定使用 Node 和 RabbitMQ。
该消息似乎已发送到 DeadExchange 中的队列,但在 WorkExchange 中的 WorkQueue 中经过的时间过后,消费者从未收到该消息。要么 bindQueue 关闭,要么死信不起作用?
我现在已经尝试了很多不同的值。有人可以指出我缺少什么吗?
var amqp = require('amqplib');
var url = 'amqp://dev.rabbitmq.com';
amqp.connect(url).then(function(conn) {
//Subscribe to the WorkQueue in WorkExchange to which the "delayed" messages get dead-letter'ed (is that a verb?) to.
return conn.createChannel().then(function(ch) {
return ch.assertExchange('WorkExchange', 'direct').then(function() {
return ch.assertQueue('WorkQueue', {
autoDelete: false,
durable: true
})
}).then(function() {
return ch.bindQueue('WorkQueue', 'WorkExchange', '');
}).then(function() {
console.log('Waiting for consume.');
return ch.consume('WorkQueue', function(msg) {
console.log('Received message.');
console.log(msg.content.toString());
ch.ack(msg);
});
}); …Run Code Online (Sandbox Code Playgroud)