场景:向RabbitMq发送消息时报错如下:
java.lang.IllegalArgumentException: SimpleMessageConverter only supports String, byte[] and Serializable payloads, received: com.example.spingbootdemo.rabbitmq.Message
at org.springframework.amqp.support.converter.SimpleMessageConverter.createMessage(SimpleMessageConverter.java:161)
at org.springframework.amqp.support.converter.AbstractMessageConverter.createMessage(AbstractMessageConverter.java:88)
at org.springframework.amqp.support.converter.AbstractMessageConverter.toMessage(AbstractMessageConverter.java:70)
at org.springframework.amqp.support.converter.AbstractMessageConverter.toMessage
原因:SimpleMessageConverter 简单模式消息发送者仅支持:String、byte[],Serializable,如果是实体类需要加上 Serializable关键字
解决:
public class Message implements Serializable {