Spring AMQP。交易信交换。发送消息给原件queue

Spring AMQP. Deal Letter Exchange. Send message to the original queue

在我的系统中,我使用与大量消费者 queue 的主题交换。每个 queue 都有自己的 non-unique 路由键(f.e。'add.#' 用于所有新实体,或者只是 '#' 以使用所有事件)。

我想添加对延迟重试失败消息的支持。我在死信交换方法中看到的最大问题是将消息直接发送到失败的 queue。 Queues 的路由键不是唯一的,即使我使用原始路由键向 Exchange 重新提交消息,它也会被其他 queue 消耗。

一个解决方案是有一个 "retry" 交换,每个应用程序都将使用唯一的路由密钥(f.e。原始 queue 名称)订阅它。但这听起来太复杂了,我想对开发人员隐藏这种基础设施的复杂性。

我想出了一个想法,要有一个过滤器来检查 'x-death' header,获取第一个 queue(首先发生错误的 queue),并仅为适当的 queue 处理消息。否则 - 确认消息。

是否可以使用 Spring AMQP 实现此行为?我正在查看 MessagePostProcessor,但如何确认来自它的消息?

如果您真的只担心目标队列,那么您需要考虑在 default exchange 中重新发布的具有以下功能的变体:

The default exchange is implicitly bound to every queue, with a routing key equal to the queue name. It is not possible to explicitly bind to, or unbind from the default exchange. It also cannot be deleted.

注意routing key equal to the queue name部分。我会考虑处理 AmqpHeaders.CONSUMER_QUEUE 并在重试过程中将其值用作路由键以重新发布到默认交换 ("")。