Properties
Properties act like additional headers that can be assigned to a
message. They allow the developer to add additional opaque information
about the message. They are also used to expose data used for message
selectors when doing message filtering. The Message
interface provides several accessor
and mutator methods for reading and writing properties. The value of a
property can be a String
, boolean
, byte
, double
, int
, long
,
or float
.
There are three basic categories of message properties:
application-specific properties, JMS-defined properties, and
provider-specific properties. Application properties are defined and
applied to Message
objects by the
application developer; the JMS extension and provider-specific
properties are additional headers that are, for the most part, automatically added by the JMS
provider.
Application-Specific Properties
Any property defined by the application developer can be an application-specific property. Application properties are set before the message is delivered. There are no predefined application properties; developers are free to define any properties that fit their needs. For example, in the chat example developed in Chapter 2, a special property could be added that identifies the user sending the message:
TextMessage message = pubSession.createTextMessage();
message.setText(text);
message.setStringProperty("username",username);
publisher.publish(message);
As an application-specific property, username
is not meaningful outside the
Chat
application; ...
Get Java Message Service, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.