当前位置:   article > 正文

RabbitMQ接收消息时报错ConditionalRejectingErrorHandler : Execution of Rabbit message listener failed_s.a.r.l.conditionalrejectingerrorhandler : executi

s.a.r.l.conditionalrejectingerrorhandler : execution of rabbit message liste

Springboot整合RabbitMQ,启动不报错,收到消息就报错

ConditionalRejectingErrorHandler : Execution of Rabbit message listener failed

  1. 2022-02-23 18:57:59.718 WARN 24956 --- [ntContainer#0-1] s.a.r.l.ConditionalRejectingErrorHandler : Execution of Rabbit message listener failed.
  2. org.springframework.amqp.rabbit.support.ListenerExecutionFailedException: Failed to convert message
  3. at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.onMessage(MessagingMessageListenerAdapter.java:155) ~[spring-rabbit-2.4.2.jar:2.4.2]
  4. at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1665) ~[spring-rabbit-2.4.2.jar:2.4.2]
  5. at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1584) ~[spring-rabbit-2.4.2.jar:2.4.2]
  6. at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1572) ~[spring-rabbit-2.4.2.jar:2.4.2]
  7. at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:1563) ~[spring-rabbit-2.4.2.jar:2.4.2]
  8. at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1507) ~[spring-rabbit-2.4.2.jar:2.4.2]
  9. at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:967) [spring-rabbit-2.4.2.jar:2.4.2]
  10. at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:914) [spring-rabbit-2.4.2.jar:2.4.2]
  11. at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$1600(SimpleMessageListenerContainer.java:83) [spring-rabbit-2.4.2.jar:2.4.2]
  12. at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.mainLoop(SimpleMessageListenerContainer.java:1291) [spring-rabbit-2.4.2.jar:2.4.2]
  13. at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1197) [spring-rabbit-2.4.2.jar:2.4.2]
  14. at java.lang.Thread.run(Thread.java:748) [na:1.8.0_281]
  15. Caused by: org.springframework.amqp.AmqpException: No method found for class [B
  16. at org.springframework.amqp.rabbit.listener.adapter.DelegatingInvocableHandler.getHandlerForPayload(DelegatingInvocableHandler.java:207) ~[spring-rabbit-2.4.2.jar:2.4.2]
  17. at org.springframework.amqp.rabbit.listener.adapter.DelegatingInvocableHandler.getMethodFor(DelegatingInvocableHandler.java:339) ~[spring-rabbit-2.4.2.jar:2.4.2]
  18. at org.springframework.amqp.rabbit.listener.adapter.HandlerAdapter.getMethodFor(HandlerAdapter.java:117) ~[spring-rabbit-2.4.2.jar:2.4.2]
  19. at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandlerAndProcessResult(MessagingMessageListenerAdapter.java:205) ~[spring-rabbit-2.4.2.jar:2.4.2]
  20. at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.onMessage(MessagingMessageListenerAdapter.java:146) ~[spring-rabbit-2.4.2.jar:2.4.2]
  21. ... 11 common frames omitted

 网上搜了一下,说是

@RabbitListener(queues="hello")

应该放在方法上,不应该放在类上。如果不放在方法上,应该设置isDefault = true

Annotation that marks a method to be the target of a Rabbit message listener on the
* specified {@link #queues()} (or {@link #bindings()}). The {@link #containerFactory()}
* identifies the
* {@link org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory
* RabbitListenerContainerFactory} to use to build the rabbit listener container. If not
* set, a <em>default</em> container factory is assumed to be available with a bean name
* of {@code rabbitListenerContainerFactory} unless an explicit default has been provided
* through configuration.

类注释上也是Annotation that marks a method to be the target of a Rabbit message listener

将 @RabbitListener(queues="hello") 放在方法上,用String接收,测试一下果然可以。

假如想用Message接收也可以。

  1. import lombok.extern.slf4j.Slf4j;
  2. import org.springframework.amqp.core.Message;
  3. import org.springframework.amqp.rabbit.annotation.RabbitHandler;
  4. import org.springframework.amqp.rabbit.annotation.RabbitListener;
  5. import org.springframework.stereotype.Component;
  6. @Slf4j
  7. @Component
  8. @RabbitListener(queues = "hello")
  9. public class Receiver {
  10. @RabbitHandler(isDefault = true)
  11. public void process(Message msg){
  12. log.info("Receive rabbitmq message:"+new String(msg.getBody()));
  13. }
  14. }

所以结论是:

将 @RabbitListener(queues="hello") 放在方法上,或者在@RabbitHandler上设置isDefault = true

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/625969
推荐阅读
相关标签
  

闽ICP备14008679号