ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Fatal message conversion error;message rejected;it will be dropped or routed to a dead letter exchan

2021-11-09 12:30:27  阅读:286  来源: 互联网

标签:conversion exchan springframework org import message com annotation


在使用rabbitmq的时候出现消息反序列化失败,如下异常:
Fatal message conversion error; message rejected; it will be dropped or routed to a dead letter exchange, if so configured
在这里插入图片描述
经过定位分析,原因是在MQ消息的生产端,设置了序列化转换Jackson2JsonMessageConverter,而默认的序列化类为SimpleMessageConverter。且在消费端没有设置反序列化转换。

解决方法:
因为消息是json串,使用String接收参数,再使用json工具类转化为对象;

import com.alibaba.nacos.client.utils.JSONUtils;
import com.atguigu.rabbit.common.constant.MqConst;
import com.atguigu.yygh.sms.service.SMSService;
import com.atguigu.yygh.vo.sms.SmsVo;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class SmsReceiver {

    @Autowired
    private SMSService smsService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = MqConst.QUEUE_SMS, durable = "true"),
            exchange = @Exchange(value = MqConst.EXCHANGE_DIRECT_SMS),
            key = {MqConst.ROUTING_SMS}
    ))
    public void send(
            String json,//接收传输过来的内容
            Message message, Channel channel) {
        SmsVo smsVo = null;
        try {
            //把json串转化为对应的对象
            //JSONUtils 包名(com.alibaba.nacos.client.utils.JSONUtils)
            smsVo = (SmsVo) JSONUtils.deserializeObject(json, SmsVo.class);
            System.out.println(smsVo);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

标签:conversion,exchan,springframework,org,import,message,com,annotation
来源: https://blog.csdn.net/weixin_53285159/article/details/121225224

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有