When rabbitmq is used, the message deserialization fails, with the following exception:
fatal message conversion error; message rejected; It will be dropped or routed to a dead letter exchange, if so configured
after location analysis, the reason is that the serialization conversion jackson2jsonmessageconverter is set on the production side of MQ messages, and the default serialization class is simplemessageconverter. And the deserialization conversion is not set on the consumer side.
Solution:
because the message is a JSON string, use string to receive parameters, and then use JSON tool class to convert it into an object;
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,//Receive the transmitted content
Message message, Channel channel) {
SmsVo smsVo = null;
try {
//Convert the json string into the corresponding object
//JSONUtils pack name(com.alibaba.nacos.client.utils.JSONUtils)
smsVo = (SmsVo) JSONUtils.deserializeObject(json, SmsVo.class);
System.out.println(smsVo);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Read More:
- Two Way Communication Error: Function two_way_comm_post_message / two_way_comm_post_message_ex faile
- Driver error 11: System 0.500000: CAN 1 : Message with ID = 630 could not be sent. Driver error 11 in TransmitCANFrame
- How to Solve Ogg start error message ogg-00014
- SAP: How to Solve error Message Number SO322
- DM backup database Error: [-7169]:bakres failed to communicate with DMAP message.
- Grpc Error: failed to unmarshal the received message proto: can‘t skip unknown wire type 7
- Jenkins error: exception message 137
- [Solved] hive Caused by: MetaException(message:Version information not found in metastore. )
- app:kaptDebugKotlin no error message [How to Solve]
- [Solved] selenium.common.exceptions.WebDriverException: Message: An unknown server-side error
- [Solved] “error_code“:500,“message“:“IO Error trying to forward REST request: java.net.ConnectException: Connection Refused
- [Solved] Error: Message failed: 554 5.2.0 STOREDRV.Submission.Exception:OutboundSpamException;
- XML read process error: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1] Message: Content not allowed in preamble
- TensorFlow issue: Expected int32, got list containing Tensors of type ‘_Message’ instead.
- Fuseki failed with message “Parse error: [line:1, col: 1] Content is not allowed in prolog.“
- [Solved] Error running query: MetaException(message:Got exception: java.net.ConnectException Call From XXXX
- [Solved] Message from debugger: debug-server is x86_64 binary running in translation, attached failed.
- Android integration of iFLYTEK’s speech recognition (voice dictation) error message “Failed to create the object, please confirm that libmsc.so is placed correctly, and createUtility is called to initialize”
- AN ERROR MESSAGE APPEARS WHEN TOMCAT DEPLOYS A NEW PROJECT: INVALID BYTE TAG IN CONSTANT POOL: 15
- [Solved] Appium Error: InvalidArgumentException: Message: invalid argument: invalid locator