Spring AMQP: Amqp.outboundAdapter to @RabbitListener, error sending response due to missing "reply-to" property

huangapple go评论89阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年1月9日 17:45:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75055458.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定