gpt4 book ai didi

java - springrabbitmq和UI层或托管bean

转载 作者:太空宇宙 更新时间:2023-11-04 13:52:53 25 4
gpt4 key购买 nike

我有一个rabbitmq监听器作为一个单独的类和JSF 2托管bean。

在我的 bean 中,我发送一条消息并需要等待结果。我无法使用 sendAndReceive... 因为我将消息发送到一个队列,但从另一个队列接收消息,因此我在发送之前分配correlationId。

所以我需要异步等待,我需要等到正确的消息到达监听器。如何在rmq中做到这一点?

最佳答案

查看javadocsource RabbitTemplate 似乎正在等待回复队列中的响应。您是否在消息中设置了“回复”属性?如果是,那么 RabbitTemplate sendAndReceive 方法应该等待“回复”队列中的响应。请务必填写replyTo field正确并测试它。

旁注:在 RabbitMQ 中,您不会将消息发送到队列。您向交易所发送消息。交换器使用绑定(bind)将消息路由到队列。使用默认或直接交换类型,看起来像是直接发送到队列,但这过于简单化了。

参见https://www.rabbitmq.com/tutorials/amqp-concepts.html了解详情。

编辑:AMQP 1.4.5.RELEASE 中似乎对此有一些修复 https://spring.io/blog/2015/05/08/spring-amqp-1-4-5-release-and-1-5-0-m1-available

Configurable Exchange/Routing Key for Replies

Previously, when using request/reply messaging with the RabbitTemplate, replies were routed to the default exchange and routed with the queue name. It is now possible to supply a reply-address with the form exchange/routingKey to route using a specific exchange and routing key.

关于java - springrabbitmq和UI层或托管bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30129744/

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