Send an object using RabbitMQ(使用 RabbitMQ 发送对象)
问题描述
我知道这个问题与问题重复使用rabbitmq发送消息不是字符串而是结构
I Understand that this question duplicates question at using rabbitmq to send a message not string but struct
如果使用第一种方法来做到这一点
if to do this using the first way
第一种方式
我有以下痕迹:
我已经检查并确认该消息在发送者类中绝对可以很好地转换为字节,但消费者无法接收它.
I've checked and shure that message is transformd to bytes absolutely well in sender class, but the consumer can't receive it.
这是我的制作人课程:
这是我的消费类:
这是我的数据类:
我似乎总是消费者收到消息,因为当我不尝试将其转换为对象时,只是写System.out.println(delivery.getBody)
它显示字节
I always seems that consumer receives messages, because when I'm not trying to transform it into the object and just write
System.out.println(delivery.getBody)
it shows bytes
推荐答案
你收到的字节数组好像是空的.这是因为:
It looks like the byte array you receive is empty. This happens because of this:
产生异常时,代码不会警告您某些内容已损坏,而是发送一个空数组.您至少应该记录错误.
When an exception is produced, the code doesn't warn you that something is broken and just sends an empty array instead. You should at least log the error.
产生异常可能是因为您试图序列化一个不可序列化的类.要使类可序列化,您必须在其声明中添加implements Serializable":
The exception is being produced probably because you are trying to serialize a class that is not serializable. To make a class serializable you have to add "implements Serializable" to its declaration:
这篇关于使用 RabbitMQ 发送对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!