Spring 整合RabbitMQ消费者接收消息乱码问题

/ /问题代码 --接收到的消息中文经常乱码
	public void handle(MessageExt message) {
		String msgContent = new String(message.getBody());
        LOGGER.info("base info report JMS=====<<<<< msgContent:{}", msgContent);
        if (StringUtil.isEmpty(msgContent)) {
            return;
        }
        
        JSONObject dataJson = JSONObject.parseObject(msgContent);
}

借鉴https://blog.csdn.net/qq_41207507/article/details/82624859
消费者接收的是message类型对象,直接输出到控制台会出现乱码问题,这事你就将byte类型转为string类型时设置字符编码为UTF-8就可以了

	public void handle(MessageExt message) {
		String msgContent = null;
		try {
			msgContent = new String(message.getBody(),"utf-8");
		} catch (UnsupportedEncodingException e) {
			LOGGER.info("base info report JMS=====<<<<< msgContent编码异常");
		}
		LOGGER.info("base info report JMS=====<<<<< msgContent:{}", msgContent);
        if (StringUtil.isEmpty(msgContent)) {
            return;
        }

        JSONObject dataJson = JSONObject.parseObject(msgContent);
      }

你可能感兴趣的:(BUG库)