NonStop JMS C++ API Programmer's Guide
Using the NSJMS C++ APIs
NonStop Server for Java Message Service C++ API Programmer’s Guide—526459-002
5-5
Populating a Message with Data
client receives a message, its properties are in read-only mode. If a client attempts to
set properties at this point, an NSJMS_Exception is thrown. Note that header fields are
distinct from properties.
Setting an application-defined string property is shown in this code fragment:
// Set an application-defined string property
pMsg->setStringProperty("test","SimpleSender");
Message Body
The message body contains the application data that is being sent. The Sun JMS API
defines these five types of message bodies:
Stream – A StreamMessage object's message body contains a stream of primitive
values. The message body is filled and read sequentially.
Map – A MapMessage object's message body contains a set of name-value pairs.
The entries can be accessed sequentially or randomly by name. The order of the
entries is undefined.
Text – A Text Message contains ASCII text. This message type can be used to
transport plain-text messages.
Object – An ObjectMessage object's message body contains an array of bytes. If
the ObjectMessage was sent by a JMS client, this message body contains a
serializable Java object.
Bytes – A BytesMessage object's message body contains a stream of
uninterpreted bytes.
Populating a TextMessage message body is shown in this code fragment:
// Populating a TextMessage message body
pMsg->setText("Sending text message");
Free Message Resources
The Session class contains the freeMessage() method for freeing message
resources. This method takes a pointer to a Message object as an argument. This
method results in the Message destructor being called, as well as any Message
subclass destructors. The method frees all memory used to store message headers,
message properties, and message bodies. Message resources should be freed after a
message is sent or received and no longer needed.
Freeing all memory used to store message headers, message properties, and
message bodies is shown in this code fragment:
// Freeing Message
pSes->freeMessage(pMsg);