问题描述:
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,导致接收的时候类型转换不对。文章来源:https://www.toymoban.com/news/detail-595504.html
@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);
}
}
解决办法:消息生产者发送的消息类型和消息消费者接收的消息类型一致即可。文章来源地址https://www.toymoban.com/news/detail-595504.html
@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);
}
}
到了这里,关于RabbitMQ Failed to convert message.No method found for class java.lang.String问题解决的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!