今天使用java对@RabbitMq消息中间件的队列进行监听的时候出现一个异常
Caused by: org.springframework.amqp.rabbit.listener.adapter.ReplyFailureException: Failed to send reply with payload 'InvocationResult [returnValue=true, returnType=boolean]'
at org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener.doHandleResult(AbstractAdaptableMessageListener.java:426) ~[spring-rabbit-2.1.8.RELEASE.jar:2.1.8.RELEASE]
at org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener.handleResult(AbstractAdaptableMessageListener.java:358) ~[spring-rabbit-2.1.8.RELEASE.jar:2.1.8.RELEASE]
at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.onMessage(MessagingMessageListenerAdapter.java:131) ~[spring-rabbit-2.1.8.RELEASE.jar:2.1.8.RELEASE]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1542) ~[spring-rabbit-2.1.8.RELEASE.jar:2.1.8.RELEASE]
... 10 common frames omitted
Caused by: org.springframework.amqp.AmqpException: Cannot determine ReplyTo message property value: Request message does not contain reply-to property, and no default response Exchange was set.
at org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener.getReplyToAddress(AbstractAdaptableMessageListener.java:506) ~[spring-rabbit-2.1.8.RELEASE.jar:2.1.8.RELEASE]
at org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener.doHandleResult(AbstractAdaptableMessageListener.java:422) ~[spring-rabbit-2.1.8.RELEASE.jar:2.1.8.RELEASE]
... 13 common frames omitted
出错的原因是:@RabbitListener注解修饰监听的方法添加了返回值。
RabbitListener修饰的方法,即队列的监听函数,不能返回任何值!否则会导致一个rabbit reply message 回复异常,
* 该异常是由于此方法返回的消息没有设置目的地
解决:只要把监听的方法的返回值改为void即可。
注意:监听方法返回值必须为void
@RabbitListener(queues = "deleteHtml") //监听deleteHtml消息队列
@RabbitHandler
public void deleteItemHtml(String ids) {
}