英文:
Spring AMQP: Amqp.outboundAdapter to @RabbitListener, error sending response due to missing "reply-to" property
问题
I have 2 Spring Boot applications (2.6.10) that need to communicate via RabbitMQ / AMQP. App #1 is Spring Integration based and uses
Amqp.outboundAdapter(rabbitTemplate).routingKey("app1-to-2")
to send messages in flow #1
Amqp.inboundAdapter(connectionFactory, "app2-to-1")
to receive messages in flow #2
App #2 is using RabbitListener to receive messages from App #1, process them immediately and return a reply:
@RabbitListener(queues={"app1-to-2"})
public MyResponse handleMessage(final MyRequest request) {
var myResponse = this.process(myRequest);
rabbitTemplate.convertAndSend("app2-to-1", myResponse);
}
However, upon receiving myRequest
in App #2, the response cannot be sent due to:
AmqpException: Cannot determine ReplyTo message property value: Request message does not contain reply-to property, and no default response Exchange was set.
Question is: Why is the routing key from convertAndSend ignored or how to set reply-to property with Amqp.outboundAdapter?
英文:
So,
I have 2 Spring Boot applications (2.6.10) that need to communicate via RabbitMQ / AMQP. App #1 is Spring Integration based and uses
Amqp.outboundAdapter(rabbitTemplate).routingKey("app1-to-2")
to send messages in flow #1
Amqp.inboundAdapter(connectionFactory, "app2-to-1")
to receive messages in flow #2
App #2 is using RabbitListener to receive messages from App #1, process them immediately and return a reply:
@RabbitListener(queues={"app1-to-2"})
public MyResponse handleMessage(final MyRequest request) {
var myResponse = this.process(myRequest);
rabbitTemplate.convertAndSend("app2-to-1",myResponse);
}
However, upon receiving myRequest
in App #2, the response cannot be send, due to:
> AmqpException: Cannot determine ReplyTo message property value: Request message does not contain reply-to property, and no default response Exchange was set.
Question is: Why is the routing key from convertAndSend ignored or how to set reply-to property with Amqp.outboundAdapter?
答案1
得分: 2
你的错误与 convertAndSend()
无关。
问题出在 @RabbitListener
方法签名上。
因为你不涉及请求-回复模式,所以你的监听方法必须具有 void
返回类型。否则,它会尝试将 MyResponse
对象发送为回复消息正文,因此我们看到错误尝试从默认策略中解析 ReplyTo
。
英文:
Your error has nothing to do with the convertAndSend()
.
It is the problem of the @RabbitListener
method signature.
Since you don't deal with request-reply pattern, your listener method must have a void
return type. Otherwise it tries to send that MyResponse
object as a reply message body and therefore we see that error trying to resolve ReplyTo
from default strategy.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论