!--a11y-->
Unpacking the Received Messages 

When a new message is received, you have to unpack it first. The procedure is the same for both the point-to-point and publish-subscribe messages types, but depends on the type of message you receive.

|
// create a byte array with the received data byte [] receivedBytes; // create an integer object to receive the data with that specified length: int dataLength; // get the data from the Bytes Message: dataLength = bytesMessage.readBytes(receivedBytes); |
The data received by the map message can be read in any order.

|
String stringData; long longData; stringData = mapMessage.getString(“message”); longData = mapMessage.getLong(“long”); |
To unpack an object message, you must make methods in the Serializable class that can transmit this data to your message. Then you have to create objects to take the data from this object:
|
String stringValue; long longValue; Class_Implementing_Serialaizable cis = new Class_Implementing_Serialaizable(); cis = objectMessage.getObject(); stringValue = cis.getString(); longValue = cis.getLong(); |
To unpack the stream message you have to get its data in the order it was sent.
|
String stringValue; long longValue; stringValue = streamMessage.readString(); longValue = streamMessage.readLong(); |

|
String text; text = textMessage.getText(); |
