RabbitMQ报错: Cannot determine ReplyTo message property v
奇闻趣事 2023-05-04 12:31www.bnfh.cn奇闻趣事
RabbitMQ报错 Cannot determine ReplyTo message property value
在使用RabbitMQ进行测试时,后台报了很多错误信息。
2023-04-08 16:21:00.526 WARN 20764 --- [.springframeork.amqp.rabbit.RabbitListenerEndpointContainer#0-1] s.a.r.l.ConditionalRejectingErrorHandler : Execution of Rabbit message listener failed.
.springframeork.amqp.rabbit.support.ListenerExecutionFailedException: Listener thre exception
at .springframeork.amqp.rabbit.listener.AbstractMessageListenerContainer.rapToListenerExecutionFailedExceptionIfNeeded(AbstractMessageListenerContainer.java:1787) ~[spring-rabbit-2.4.9.jar:2.4.9]
at .springframeork.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1677) ~[spring-rabbit-2.4.9.jar:2.4.9]
at .springframeork.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1592) ~[spring-rabbit-2.4.9.jar:2.4.9]
at .springframeork.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1580) ~[spring-rabbit-2.4.9.jar:2.4.9]
at .springframeork.amqp.rabbit.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:1571) ~[spring-rabbit-2.4.9.jar:2.4.9]
at .springframeork.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1515) ~[spring-rabbit-2.4.9.jar:2.4.9]
at .springframeork.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:994) [spring-rabbit-2.4.9.jar:2.4.9]
at .springframeork.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:941) [spring-rabbit-2.4.9.jar:2.4.9]
at .springframeork.amqp.rabbit.listener.SimpleMessageListenerContainer.aess$1600(SimpleMessageListenerContainer.java:85) [spring-rabbit-2.4.9.jar:2.4.9]
at .springframeork.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.mainLoop(SimpleMessageListenerContainer.java:1319) [spring-rabbit-2.4.9.jar:2.4.9]
at .springframeork.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1225) [spring-rabbit-2.4.9.jar:2.4.9]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_281]
Caused by: .springframeork.amqp.rabbit.listener.adapter.ReplyFailureException: Failed to send reply ith payload 'InvocationResult [returnValue=my message, returnType=class java.lang.String, bean=.example.hello.listener.RabbitMQListener@435ce306, method=public java.lang.String .example.hello.listener.RabbitMQListener.handleMsg(java.lang.String)]'
at .springframeork.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener.doHandleResult(AbstractAdaptableMessageListener.java:492) ~[spring-rabbit-2.4.9.jar:2.4.9]
at .springframeork.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener.handleResult(AbstractAdaptableMessageListener.java:416) ~[spring-rabbit-2.4.9.jar:2.4.9]
at .springframeork.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandlerAndProcessResult(MessagingMessageListenerAdapter.java:211) ~[spring-rabbit-2.4.9.jar:2.4.9]
at .springframeork.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.onMessage(MessagingMessageListenerAdapter.java:148) ~[spring-rabbit-2.4.9.jar:2.4.9]
at .springframeork.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1673) ~[spring-rabbit-2.4.9.jar:2.4.9]
... 10 mon frames omitted
Caused by: .springframeork.amqp.AmqpException: Cannot determine ReplyTo message property value: Request message does not contain reply-to property, and no default response Exchange as set.
at .springframeork.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener.getReplyToAddress(AbstractAdaptableMessageListener.java:592) ~[spring-rabbit-2.4.9.jar:2.4.9]
at .springframeork.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener.doHandleResult(AbstractAdaptableMessageListener.java:488) ~[spring-rabbit-2.4.9.jar:2.4.9]
... 14 mon frames omitted
仔细检查了下配置,没有发现问题。
看报错信息是“ReplyTo message ”,貌似是返回值有问题。
检查了下出现问题的方法,这个方法确实有个返回值。
@Component
public class RabbitMQListener {
@RabbitListener(queues = "myqueue")
public String handleMsg(String msg){
System.out.println(msg);
return msg;
}
}
将这个方法给我无返回值后,就没有再报错。
看来使用@RabbitListener时不能有返回值。
正确的方式如下
@Component
public class RabbitMQListener {
@RabbitListener(queues = "myqueue")
public void handleMsg(String msg){
System.out.println(msg);
}
}