RabbitMQ 中的死信死信消息 [英] Dead-lettering dead-lettered messages in RabbitMQ
问题描述
这是我们这里的内容:
- 主题交换
DLE
,旨在成为死信交换 - 主题交换
E
,即主要"交换 - 几个队列 (
EQ1
, ...,EQn
) 绑定到E
(并用x-dead-letter 初始化-exchange = DLE
),每个都有自己的路由密钥.这些队列是被消费的队列. - 对于每个
EQn
,都有一个DLEQn
(用x-dead-letter-exchange = E
和x-message 初始化-ttl = 5000
),绑定到DLE
与EQn
具有相同的路由键.这些队列不会被从 消耗
- Topic Exchange
DLE
, which is intended to be a Dead-Letter Exchange - Topic Exchange
E
, which is the "main" Exchange - Several Queues (
EQ1
, ...,EQn
) bound toE
(and initialized withx-dead-letter-exchange = DLE
), each with own Routing Key. These queues are the ones being consumed from. - For each
EQn
, there's aDLEQn
(initialized withx-dead-letter-exchange = E
andx-message-ttl = 5000
), bound toDLE
with the same routing key asEQn
. These queues are not being consumed from
我想要的是以下内容:如果消费者无法处理来自 EQn
的消息,它会使用 requeue: false
对消息进行 Nacks 并到达 DLEQn
- 即到死信交换上的适当队列.现在,我希望此消息在 DLEQn
上停留一段时间,然后路由回原始队列 EQn
以再次进行处理.
What I want is the following: if a consumer cannot process a message from EQn
, it Nacks the message with requeue: false
and it gets to the DLEQn
- that is, to an appropriate queue on the Dead-Letter Exchange. Now, I want this message to sit on the DLEQn
for some time and then get routed back to the original queue EQn
to be processed again.
尽我所能,我无法使重新传递到原始队列"工作.我看到消息位于 DLEQn
中,所有正确的标头和路由密钥都完好无损,但在 TTL 到期后,它们就消失得无影无踪了.
Try as I might, I could not get the "redelivery to the original queue" working. I see that messages sit in the DLEQn
with all the right headers and Routing Key intact, but after TTL expires they just vanish into thin air.
我在这里做错了什么?
推荐答案
是的,您可以这样做.我们目前正在生产中这样做,并且效果很好.代码太长,无法包含在此处,但我将向您展示我创建的代表该过程的图表.基本思想是第一个 DLX 有一个 TTL,一旦 TTL 到期,消息就会进入第二个队列,重新发送回原始队列.
Yes, you can do this. We are currently doing this in production and it works great. The code is too long to include here but I will show you the diagram I created that represents the process. The basic idea is that the First DLX has a TTL, once that TTL expires the message goes into a 2nd queue to be re-sent back into the original.
这篇关于RabbitMQ 中的死信死信消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!