Kbase 20796: SonicMQ: Supported message types
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  05/04/2001 |
|
20796
Title: SonicMQ: Supported Message Types
SUMMARY:
This Knowledge Base applies to SonicMQ Version 2000.1 and Version 3.0. It defines the SonicMQ supported message types.
EXPLANATION:
The JMS specification defines five types of messages. SonicMQ supports these message types, plus it provides an XML message type as an extension of the JMS Text type. The list includes:
- BytesMessage:
A stream of un-interpreted bytes. This message type exists
to support cases where the contents of the message are
shared with applications that cannot read Java types or
16-bit Unicode encodings.
It is also useful when the information to send already
exists in binary form. The following code fragment is an
example of creating a BytesMessage:
try {
javax.jms.BytesMessage msg = session.createBytesMessage();
String description = "This is a bytes message.";
msg.writeUTF ("This is the ProductName and ProductType.");
}
- MapMessage:
A set of name-value pairs where names are strings and values
are Java primitive types. The entries can be accessed
sequentially or randomly by name.
An example of MapMessage use is a message that describes a
new product. The names in the MapMessage correlate to
columns in a database table in which the consumer stores the
information. The following code fragment is an example of
creating a MapMessage:
try {
javax.jms.MapMessage msg = session.createMapMessage();
String description = "This is a map message.";
msg.setString ("ProductName", "ProductType");
}
- ObjectMessage:
A message that contains a serializable Java object. An
ObjectMessage is useful when both JMS clients are Java
applications or applets with access to the same class
definition. The following code fragment is an example of
creating an ObjectMessage.
Product newProduct = new Product(productName, description);
try {
javax.jms.ObjectMessage msg = session.createObjectMessage();
msq.setObject ( newProduct );
}
- StreamMessage:
A stream of Java un-keyed primitive values that is filled
and accessed sequentially. Since a StreamMessage contains
only raw data and no keys, it takes up less space than an
equivalent MapMessage. The following code fragment is an
example of creating a StreamMessage:
try {
javax.jms.StreamMessage msg = session.createStreamMessage();
String description = "This is a stream message.";
msg.writString ("This is the ProductName and ProductType");
}
- TextMessage:
A message that contains a java.lang.String or string. Use a
TextMessage when the message content does not require a
particular structure, for example; when the message body is
printed or copied by the consumer. The following code
fragment is an example of creating a TextMessage:
String content = "This is a text message.";
try {
javax.jms.TextMessage msg = session.createTextMessage();
msg.setText( content );
}
- XMLMessage:
A message that contains a string that represents the XML
tree that can be parsed as an XML document. An XMLMessage is
an extension of the TextMessage and is used to send a
message that contains XML text in a java.lang.String.
TextMessage inherits from Message, and adds a text message
body. XMLMessage then allows access to the XML text's
Document Object Model (DOM). An implementation of the DOM
interface is instantiated when the developer wants to access
the XML message body using the DOM. The following code
fragment is an example of creating a XMLMessage:
{
progress.message.jclient.XMLMessage xMsg =
progress.message.jclient.Session)session).createXMLMessage();
StringBuffer msg = new StringBuffer();
msg.append ("<?xml version=\"1.0\"?>\n");
msg.append ("<Product>\n");
msg.append ("<ProductName name='ProductName'/>\n");
msg.append ("</Product>\n");
xMsg.setText( msg.toString() );
}
Reference to Written Documentation:
SonicMQ Programming Guide.
SonicMQ Getting Started Guide.