Suppose you have a message queue, used to send and receive messages, and is the internal message queue, a program is not a message queue between two programs,
Assume that each message in the message queue data structure is as follows, there are two members, one is the message type, the other one is the message content,
Struct MSG_ITEM {
The int type.
XXX body;//??
};
I have some doubts about the body type definition, because there are all kinds of news, can't use a unified type to define the body, don't know how to solve the problems in Java,
One of my guess is to use the byte stream for defining the body, when sending a message, put a message type serialization, become a byte stream, when receiving a message, and then read the byte stream serialization, composed of a single message types,
Note: I didn't study Java, c + +, I studied in c + +, the body can be defined as a void * type, when receiving a message, type void * can be forced into a message type pointer
CodePudding user response:
Java general message serialization into a json string, and then use string again into object consumptionCodePudding user response:
We have a generic??CodePudding user response:
The object can be loaded,CodePudding user response:
If it is a different queue, generics can help you, if the same queue, then the json string and the name of the classCodePudding user response:
For Java, can convert json type of string to the corresponding object type, so the body generally defined as a type string in Java