Creating messages

To create a message, you must first create an instance of either a queue or topic session. See “Creating sessions” for details. To create a text message, use this syntax:

// Create a text message using a QueueSession

javax.jms.TextMessage queueTextMsg =
   queueSession.createTextMessage(“Text message”);

// Create a text message using a TopicSession

javax.jms.TextMessage topicTextMsg = 
   topicSession.createTextMessage(“Text message”);

EAServer supports six message types that a message producer can send or publish. Table 31-1 describes the message types and the javax.jms.Session interface APIs used to create instances of each.

Table 31-1: JMS message types

Message type

Create message API

Comments

Plain

Session.createMessage

Creates a message without a message body.

Text

Session.createTextMessage

Creates a message that can contain a string in the message body.

Object

Session.createObjectMessage

Creates a message that can contain a serializable Java object in the message body.

Stream

Session.createStreamMessage

Creates a message that can contain a stream of Java primitives in the message body. Fill and read the message sequentially.

Map

Session.createMapMessage

Creates a message whose body can contain a set of name-value pairs where names are Strings and values are Java primitive types.

Bytes

Session.createBytesMessage

Creates a message that can contain a stream of uninterpreted bytes in the message body.

To improve interoperability with non-Java clients or components and to improve message receivers’ ability to filter messages, Sybase recommends that you use either plain messages or text messages. Selectors allow you to filter messages based on the text in the message properties. You cannot filter messages based on the text in the message body. Therefore, message text in the message properties, instead of the message body, enables the message receivers to filter messages more efficiently.

For more information about the message types, see the JMS API documentation.