在 spring-amqp 中重启生产者后,有没有办法从回复队列中获取消息
Is there a way to get messages from reply queue after restart of the producer in spring-amqp
所以我的场景如下:
- 生产者将使用 AsyncRabbitTemplate#sendAndReceive 向队列发送消息
- 消费者将处理消息并将回复发送到回复队列
所以直到现在,当生产者启动并且 运行 时,一切都会正常工作。回复队列的消息会收到,一切正常
但是当生产者在收到所有回复之前就宕机时,以后就没有办法得到它们了。所有待处理的回复都会产生警告 "No pending reply - perhaps timed out:"。当我查看代码时,我完全理解为什么会发生这种情况。
有没有办法持久存储传入回复消息的信息?我是在做一些完全错误的事情,还是无法用 spring-amqp 涵盖我的用例?
所以问题是在生产者重启后从固定回复队列接收回复的最佳方式是什么。
目前不支持持久化待回复信息;通常在 request/reply 场景中,如果请求者死亡,则回复毫无意义。但我可以看到有些情况可能并非如此。
您可以简单地使用 RabbitTemplate
send()
并使用配置为处理和路由回复的侦听器容器,而不是使用异步模板。
您需要进行自己的 request/reply 关联(例如使用 correlationId
header),在某处保留待处理的回复关联。
Spring Integration provides a Metadatastore
abstraction 有几个可能适合的实现。
所以我的场景如下:
- 生产者将使用 AsyncRabbitTemplate#sendAndReceive 向队列发送消息
- 消费者将处理消息并将回复发送到回复队列 所以直到现在,当生产者启动并且 运行 时,一切都会正常工作。回复队列的消息会收到,一切正常
但是当生产者在收到所有回复之前就宕机时,以后就没有办法得到它们了。所有待处理的回复都会产生警告 "No pending reply - perhaps timed out:"。当我查看代码时,我完全理解为什么会发生这种情况。 有没有办法持久存储传入回复消息的信息?我是在做一些完全错误的事情,还是无法用 spring-amqp 涵盖我的用例?
所以问题是在生产者重启后从固定回复队列接收回复的最佳方式是什么。
目前不支持持久化待回复信息;通常在 request/reply 场景中,如果请求者死亡,则回复毫无意义。但我可以看到有些情况可能并非如此。
您可以简单地使用 RabbitTemplate
send()
并使用配置为处理和路由回复的侦听器容器,而不是使用异步模板。
您需要进行自己的 request/reply 关联(例如使用 correlationId
header),在某处保留待处理的回复关联。
Spring Integration provides a Metadatastore
abstraction 有几个可能适合的实现。