赞
踩
org.springframework.amqp.rabbit.support.ListenerExecutionFailedException: Failed to convert message
Caused by: org.springframework.amqp.AmqpException: No method found for class java.lang.String
1、消息生产者发送的消息类型为String,消息消费者接收的消息类型为Message,导致接收的时候类型转换不对。
- @Component
- public class MessageProvider {
- @Autowired
- private RabbitTemplate rabbitTemplate;
-
- public void send(String exchange,String routingKey,String content){
- rabbitTemplate.convertAndSend(exchange,routingKey,content);
- }
- }
- @Component
- @RabbitListener(queues = "directqueue2")
- public class MessageReceiver {
- @RabbitHandler
- public void process(Message message) throws InterruptedException {
- Thread.sleep(1000);
- }
- }
解决办法:消息生产者发送的消息类型和消息消费者接收的消息类型一致即可。
- @Component
- public class MessageProvider {
- @Autowired
- private RabbitTemplate rabbitTemplate;
-
- public void send(String exchange,String routingKey,String content){
- rabbitTemplate.convertAndSend(exchange,routingKey,content.getBytes());
- }
- }
- @Component
- @RabbitListener(queues = "directqueue2")
- public class MessageReceiver {
- @RabbitHandler
- public void process(byte[] message) throws InterruptedException {
- Thread.sleep(1000);
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。