gpt4 book ai didi

architecture - RabbitMQ中需要单独的死信交换吗?

转载 作者:行者123 更新时间:2023-12-04 17:24:31 27 4
gpt4 key购买 nike

我已经为我的队列设置了一个死信路由,以延迟几秒钟重新排列被拒绝的消息,防止临时消费者错误阻塞队列。我已经设置了这个,所以工作队列和死信队列都绑定(bind)到同一个交换:
Flow chart depicting my intended flow of messages. Description below.

Externally produced, incoming messages are routed to the exchange, which places them in the work queue. During processing the message, a consumer might fail due to some temporary errors (think a crawler receiving an error 500 from a website).
Instead of rejecting the message and having itplaced at the head of the queue again (leading to an infinite loop), we route rejected messages (with requeue=0) to the exchange, adding the dead letter queue as the routing key. Here, every message receives a TTL of X seconds, after which it will be rejected, and therefore routed back to the exchange with the routing key se to the original work queue.


不过看网上的文献和例子,大家似乎都推荐路由到单独的死信交换:
Flow chart depicting the commonly used flow of messages. Description below.

Externally produced, incoming messages are routed to the work exchange, which places them in the work queue. If a consumer fails, messages are rejected (with requeue=0) and will be routed to the dead letter exchange. The dead letter exchange routes the messages to the dead letter queue, where the message TTL will expire, and the again-rejected messages will be routed back to the work exchange.



与第一个设计相比,第二个设计是否有一些重要的优势?我无法识别任何一个,但是我对 RabbitMQ 不太有信心。

最佳答案

这取决于您使用的交换类型以及您需要执行的其他路由。如果您对原始消息和重新排队的消息使用相同的交换,则需要区分:

  • 新消息,可能被路由到多个队列,或者根本没有
  • 失败的消息,应该只路由到延迟队列
  • 延迟消息,应该只路由到失败的单个队列

  • my implementation of this pattern我使用了两个额外的交换器(两者都是按需动态声明的),以便它尽可能独立于原始路由配置:
  • 原始消息由消费者确认,并手动重新发布,以“开始”交换。这提供了一些额外的灵活性,例如在消息上设置自定义 header ,以及将具有不同 TTL 的多个延迟队列附加到同一工作队列。
  • “开始”交换是扇出交换,绑定(bind)到特定的“等待”队列,如第二张图所示。
  • 当消息 TTL 在“等待”队列中到期时,它被路由到一个单独的“完成”交换,设置为死信交换。
  • 该交换也是扇出交换,仅绑定(bind)到原始工作队列。这确保不会为第一次成功处理它的其他队列创建额外的消息副本。
  • 因此,消息会返回到原始队列中,并带有其原始路由键。
  • 关于architecture - RabbitMQ中需要单独的死信交换吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64183725/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com