Processing Messages

Use

There are several message types defined by the JMS specification that the applications can create and receive, all implementing the javax.jms.Message interface.

  • Generic Message - consists only of a message header and properties.

  • Byte Message - represents an array of bytes.

  • Map Message - contains a set of name-value pairs.

  • Object Message - has a payload that is a Serializable Java object.

  • Stream Message - contains a stream of Java primitive values.

  • Text Message - contains java.lang.String object.

Procedure

Processing Byte Message

               // 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);

            

Processing Map Message

               String stringData;

long longData;

stringData = mapMessage.getString("message");

longData = mapMessage.getLong("long");

            

Processing Objects Message

               String stringValue;

long longValue;

Class_Implementing_Serialaizable cis = new Class_Implementing_Serialaizable();

cis =  objectMessage.getObject();

stringValue = cis.getString();

longValue = cis.getLong();
 

            

Processing Stream Message

               String stringValue;

long longValue;

stringValue = streamMessage.readString();

longValue = streamMessage.readLong();

            

Processing Text Message

               String text;

text = textMessage.getText();