死信交换 RabbitMQ 丢弃消息 [英] Dead letter exchange RabbitMQ dropping messages
问题描述
我正在尝试在 RabbitMQ 中实现一个 dlx 队列.场景很简单我有 2 个队列:1) 活着2) dead (x-dead-letter-exchange: "immediate", x-message-ttl: 5000)
I'm trying to implement a dlx queue in RabbitMQ. The scenario is quite easy I have 2 queues: 1) alive 2) dead (x-dead-letter-exchange: "immediate", x-message-ttl: 5000)
以及绑定到 1) 活着的立即"交换
and an exchange "immediate" that is bound to 1) alive
我试图运行这个例子:http://blog.james-carr.org/2012/03/30/rabbitmq-sending-a-message-to-be-consumed-later/但似乎消息在 ttl 过期后被丢弃并且它们没有在交换中发布,所以我的活动队列总是空的.
I tried to run this example: http://blog.james-carr.org/2012/03/30/rabbitmq-sending-a-message-to-be-consumed-later/ but it seems that the messages are dropped after the ttl expires and they dont get published on the exchange, so my alive queue is always empty.
我还尝试在管理控制台中手动创建队列,我得到了相同的行为.
I also tried to create the queues by hand in the management console and I get the same behaviour.
我使用 Ubuntu/rabbitmq 3.0.0 以及 Mac OS X 和 rabbitmq 2.8.7 对其进行了测试
I tested it with Ubuntu/rabbitmq 3.0.0 and with Mac OS X and rabbitmq 2.8.7
我错过了什么吗?
推荐答案
当消息在 RabbitMQ 中消失"时,问题通常归结为绑定.因此,为了让您的示例正常工作,我执行了以下操作:
When messages 'disappear' in RabbitMQ the problem is usually down to the bindings. So, to get your example working I did the following:
创建了 2 个队列,活的,死的(使用 TTL 和 DLX)
Created 2 queues, alive, dead (with the TTL and DLX)
创建了一个名为 immediate 的 DIRECT 类型的交换
Created an exchange called immediate of type DIRECT
使用路由键dead"在交换立即"和活动"队列之间创建了一个绑定 - 这样做的原因是,消息进入死队列的路由键(如果使用默认值exchange is 'dead' 这需要在死信交换的绑定中匹配).
Created a binding between the exchange "immediate" and the queue "alive" with a routing key "dead" - the reason for this is because, the routing key for messages into the dead queue (if using the default exchange is 'dead' this needs to match in the binding on the dead letter exchange).
这里的重要部分是 immediate 交换和 alive 队列之间的绑定.
The important part here is in the binding between the immediate exchange and the alive queue.
为了测试我将消息发布到死队列中,我可以看到它短暂出现在死队列中,然后出现在活动队列中.
To test I published a message into the dead queue, I can see it appear in the dead queue briefly then appear in the alive queue.
这篇关于死信交换 RabbitMQ 丢弃消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!