|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
The Message interface is the root interface of all JMS messages. It
defines the JMS header and the acknowledge
method used for
all messages.
Most MOM products treat messages as lightweight entities that consist of a header and a payload. The header contains fields used for message routing and identification; the payload contains the application data being sent.
Within this general form, the definition of a message varies significantly across products. It would be quite difficult for JMS to support all of these message models.
With this in mind, the JMS message model has the following goals:
JMS Messages are composed of the following parts:
JMS defines five types of message body:
The JMSCorrelationID header field is used for linking one message with another. It typically links a reply message with its requesting message.
JMSCorrelationID can hold either a provider-specific message ID, an application-specific String or a provider-native byte[] value.
A Message contains a built-in facility for supporting application defined property values. In effect, this provides a mechanism for adding application specific header fields to a message.
Properties allow an application, via message selectors, to have a JMS provider select/filter messages on its behalf using application-specific criteria.
Property names must obey the rules for a message selector identifier.
Property values can be boolean, byte, short, int, long, float, double, and String.
Property values are set prior to sending a message. When a client
receives a message, its properties are in read-only mode. If a
client attempts to set properties at this point, a
MessageNotWriteableException is thrown. If clearProperties
is
called, the properties can now be both read from and written to.
A property value may duplicate a value in a message's body or it may not. Although JMS does not define a policy for what should or should not be made a property, application developers should note that JMS providers will likely handle data in a message's body more efficiently than data in a message's properties. For best performance, applications should only use message properties when they need to customize a message's header. The primary reason for doing this is to support customized message selection.
Message properties support the following conversion table. The marked
cases must be supported. The unmarked cases must throw a JMSException. The
String to primitive conversions may throw a runtime exception if the
primitives valueOf()
method does not accept it as a valid
String representation of the primitive.
A value written as the row type can be read as the column type.
| | boolean byte short int long float double String |---------------------------------------------------------- |boolean | X X |byte | X X X X X |short | X X X X |int | X X X |long | X X |float | X X X |double | X X |String | X X X X X X X X |----------------------------------------------------------
In addition to the type-specific set/get methods for properties, JMS
provides the setObjectProperty
and
getObjectProperty
methods. These support the same set of
property types using the objectified primitive values. Their purpose is
to allow the decision of property type to made at execution time rather
than at compile time. They support the same property value conversions.
The setObjectProperty
method accepts values of class
Boolean, Byte, Short, Integer, Long, Float, Double and String. An attempt
to use any other class must throw a JMSException.
The getObjectProperty
method only returns values of class
Boolean, Byte, Short, Integer, Long, Float, Double and String.
The order of property values is not defined. To iterate through a
message's property values, use getPropertyNames
to retrieve
a property name enumeration and then use the various property get methods
to retrieve their values.
A message's properties are deleted by the clearProperties
method. This leaves the message with an empty set of properties.
Getting a property value for a name which has not been set returns a
null value. Only the getStringProperty
and
getObjectProperty
methods can return a null value. The other
property get methods must throw a
java.lang.NullPointerException
if they are used to get a
non-existent property.
JMS reserves the `JMSX' property name prefix for JMS defined properties.
The full set of these properties is defined in the Java Message Service
specification. New JMS defined properties may be added in later versions
of JMS. Support for these properties is optional. The
String[] ConnectionMetaData.getJMSXPropertyNames
method
returns the names of the JMSX properties supported by a connection.
JMSX properties may be referenced in message selectors whether or not they are supported by a connection. They are treated like any other absent property.
JSMX properties `set by provider on send' are available to both the producer and the consumers of the message. JSMX properties `set by provider on receive' are only available to the consumers.
JMSXGroupID and JMSXGroupSeq are simply standard properties clients should use if they want to group messages. All providers must support them. Unless specifically noted, the values and semantics of the JMSX properties are undefined.
JMS reserves the `JMS_ The purpose of provider-specific properties is to provide special
features needed to support JMS use with provider-native clients. They
should not be used for JMS to JMS messaging.
JMS provides a set of message interfaces that define the JMS message
model. It does not provide implementations of these interfaces.
Each JMS provider supplies a set of message factories with its Session
object for creating instances of these messages. This allows a provider
to use implementations tailored to their specific needs.
A provider must be prepared to accept message implementations that are
not its own. They may not be handled as efficiently as their own
implementations; however, they must be handled.
A JMS message selector allows a client to specify by message header the
messages it's interested in. Only messages whose headers match the
selector are delivered. The semantics of not delivered differ a bit
depending on the MessageConsumer being used (see QueueReceiver and
TopicSubscriber).
Message selectors cannot reference message body values.
A message selector matches a message when the selector evaluates to
true when the message's header field and property values are substituted
for their corresponding identifiers in the selector.
A message selector is a String, whose syntax is based on a subset of
the SQL92 conditional expression syntax.
The order of evaluation of a message selector is from left to right
within precedence level. Parenthesis can be used to change this order.
Predefined selector literals and operator names are written here in
upper case; however, they are case insensitive.
A selector can contain:
JMS providers are required to verify the syntactic correctness of a
message selector at the time it is presented. A method providing a
syntactically incorrect selector must result in a JMSException.
The following message selector selects messages with a message type
of car and color of blue and weight greater than 2500 lbs:
"JMSType = `car' AND color = `blue' AND weight > 2500"
As noted above, property values may be NULL. The evaluation of
selector expressions containing NULL values is defined by SQL 92 NULL
semantics. A brief description of these semantics is provided here.
SQL treats a NULL value as unknown. Comparison or arithmetic with
an unknown value always yields an unknown value.
The IS NULL and IS NOT NULL operators convert an unknown value into
the respective TRUE and FALSE values.
The boolean operators use three valued logic as defined by the
following tables:
The definition of the AND operator
The definition of the OR operator
The definition of the NOT operator
When used in a message selector JMSDeliveryMode is treated as having
the values `PERSISTENT' and `NON_PERSISTENT'.
Although SQL supports fixed decimal comparison and arithmetic, JMS
message selectors do not. This is the reason for restricting exact
numeric literals to those without a decimal (and the addition of
numerics with a decimal as an alternate representation for an
approximate numeric values).
SQL comments are not supported.
The messageID header field contains a value that uniquely
identifies each message sent by a provider.
When a message is sent, messageID can be ignored. When
the send method returns it contains a provider-assigned value.
A JMSMessageID is a String value which should function as a
unique key for identifying messages in a historical repository.
The exact scope of uniqueness is provider defined. It should at
least cover all messages for a specific installation of a
provider where an installation is some connected set of message
routers.
All JMSMessageID values must start with the prefix `ID:'.
Uniqueness of message ID values across different providers is
not required.
Since message ID's take some effort to create and increase a
message's size, some JMS providers may be able to optimize message
overhead if they are given a hint that message ID is not used by
an application. JMS message Producers provide a hint to disable
message ID. When a client sets a Producer to disable message ID
they are saying that they do not depend on the value of message
ID for the messages it produces. These messages must either have
message ID set to null or, if the hint is ignored, messageID must
be set to its normal unique value. Providers set this field when a message is sent. This operation
can be used to change the value of a message that's been received. The JMSTimestamp header field contains the time a message was
handed off to a provider to be sent. It is not the time the
message was actually transmitted because the actual send may occur
later due to transactions or other client side queueing of messages.
When a message is sent, JMSTimestamp is ignored. When the send
method returns it contains a a time value somewhere in the interval
between the call and the return. It is in the format of a normal
Java millis time value.
Since timestamps take some effort to create and increase a
message's size, some JMS providers may be able to optimize message
overhead if they are given a hint that timestamp is not used by an
application. JMS message Producers provide a hint to disable
timestamps. When a client sets a producer to disable timestamps
they are saying that they do not depend on the value of timestamp
for the messages it produces. These messages must either have
timestamp set to null or, if the hint is ignored, timestamp must
be set to its normal value. Providers set this field when a message is sent. This operation
can be used to change the value of a message that's been received. The use of a byte[] value for JMSCorrelationID is non-portable. If a provider supports the native concept of correlation id, a
JMS client may need to assign specific JMSCorrelationID values to
match those expected by non-JMS clients. JMS providers without native
correlation id values are not required to support this (and the
corresponding get) method; their implementation may throw
java.lang.UnsupportedOperationException).
The use of a byte[] value for JMSCorrelationID is non-portable. A client can use the JMSCorrelationID header field to link one
message with another. A typically use is to link a response message
with its request message.
JMSCorrelationID can hold one of the following:
Since each message sent by a JMS provider is assigned a message ID
value it is convenient to link messages via message ID. All message ID
values must start with the `ID:' prefix.
In some cases, an application (made up of several clients) needs to
use an application specific value for linking messages. For instance,
an application may use JMSCorrelationID to hold a value referencing
some external information. Application specified values must not start
with the `ID:' prefix; this is reserved for provider-generated message
ID values.
If a provider supports the native concept of correlation ID, a JMS
client may need to assign specific JMSCorrelationID values to match
those expected by non-JMS clients. A byte[] value is used for this
purpose. JMS providers without native correlation ID values are not
required to support byte[] values. The use of a byte[] value for
JMSCorrelationID is non-portable. This method is used to return correlation id values that are
either provider-specific message ID's or application-specific Strings. The replyTo header field contains the destination where a reply
to the current message should be sent. If it is null no reply is
expected. The destination may be either a Queue or a Topic.
Messages with a null replyTo value are called JMS datagrams.
Datagrams may be a notification of some change in the sender (i.e.
they signal a sender event) or they may just be some data the sender
thinks is of interest.
Messages with a replyTo value are typically expecting a response.
A response may be optional, it is up to the client to decide. These
messages are called JMS requests. A message sent in response to a
request is called a reply.
In some cases a client may wish to match up a request it sent earlier
with a reply it has just received. This can be done using the
correlationID. The destination field contains the destination to which the
message is being sent.
When a message is sent this value is ignored. After completion
of the send method it holds the destination specified by the send.
When a message is received, its destination value must be
equivalent to the value assigned when it was sent. Providers set this field when a message is sent. This operation
can be used to change the value of a message that's been received. Providers set this field when a message is sent. This operation
can be used to change the value of a message that's been received. If a client receives a message with the redelivered indicator set,
it is likely, but not guaranteed, that this message was delivered to
the client earlier but the client did not acknowledge its receipt at
that earlier time. This field is set at the time the message is delivered. This
operation can be used to change the value of a message that's
been received. Some JMS providers use a message repository that contains the
definition of messages sent by applications. The type header field
contains the name of a message's definition.
JMS does not define a standard message definition repository nor
does it define a naming policy for the definitions it contains. JMS
clients should use symbolic values for type that can be configured
at installation time to the values defined in the current providers
message repository.
JMS clients should assign a value to type whether the application
makes use of it or not. This insures that it is properly set for
those providers that require it. When a message is sent, expiration is left unassigned. After
completion of the send method, it holds the expiration time of the
message. This is the sum of the time-to-live value specified by the
client and the GMT at the time of the send.
If the time-to-live is specified as zero, expiration is set to
zero which indicates the message does not expire.
When a message's expiration time is reached, a provider should
discard it. JMS does not define any form of notification of message
expiration.
Clients should not receive messages that have expired; however,
JMS does not guarantee that this will not happen. Providers set this field when a message is sent. This operation
can be used to change the value of a message that's been received. JMS defines a ten level priority value with 0 as the lowest
priority and 9 as the highest. In addition, clients should consider
priorities 0-4 as gradations of normal priority and priorities 5-9
as gradations of expedited priority.
JMS does not require that a provider strictly implement priority
ordering of messages; however, it should do its best to deliver
expedited messages ahead of normal messages. Providers set this field when a message is sent. This operation
can be used to change the value of a message that's been received. Note that this method can be used to return in objectified format,
an object that had been stored as a property in the Message with the
equivalent Note that this method only works for the objectified primitive
object types (Integer, Double, Long ...) and String's. All JMS messages support the acknowledge() method for use when a
client has specified that a JMS consumers messages are to be
explicitly acknowledged.
JMS defaults to implicit message acknowledgement. In this mode,
calls to acknowledge() are ignored.
Acknowledgment of a message automatically acknowledges all
messages previously received by the consumer. Clients may
individually acknowledge messages or they may choose to acknowledge
messages in application defined groups (which is done by acknowledging
the last received message in the group).
Messages that have been received but not acknowledged may be
redelivered to the consumer.
| AND | T | F | U
+------+-------+-------+-------
| T | T | F | U
| F | F | F | F
| U | U | F | U
+------+-------+-------+-------
| OR | T | F | U
+------+-------+-------+--------
| T | T | T | T
| F | T | F | U
| U | T | U | U
+------+-------+-------+-------
| NOT
+------+------
| T | F
| F | T
| U | U
+------+-------
BytesMessage
,
MapMessage
,
ObjectMessage
,
StreamMessage
,
TextMessage
Field Summary
static int
DEFAULT_DELIVERY_MODE
The default delivery mode value.
static int
DEFAULT_PRIORITY
The default priority value.
static int
DEFAULT_TIME_TO_LIVE
The default time to live value.
Method Summary
void
acknowledge()
Acknowledge this and all previous messages received.
void
clearBody()
Clear out the message body.
void
clearProperties()
Clear a message's properties.
boolean
getBooleanProperty(java.lang.String name)
Return the boolean property value with the given name.
byte
getByteProperty(java.lang.String name)
Return the byte property value with the given name.
double
getDoubleProperty(java.lang.String name)
Return the double property value with the given name.
float
getFloatProperty(java.lang.String name)
Return the float property value with the given name.
int
getIntProperty(java.lang.String name)
Return the integer property value with the given name.
java.lang.String
getJMSCorrelationID()
Get the correlation ID for the message.
byte[]
getJMSCorrelationIDAsBytes()
Get the correlation ID as an array of bytes for the message.
int
getJMSDeliveryMode()
Get the delivery mode for this message.
Destination
getJMSDestination()
Get the destination for this message.
long
getJMSExpiration()
Get the message's expiration value.
java.lang.String
getJMSMessageID()
Get the message ID.
int
getJMSPriority()
Get the message priority.
boolean
getJMSRedelivered()
Get an indication of whether this message is being redelivered.
Destination
getJMSReplyTo()
Get where a reply to this message should be sent.
long
getJMSTimestamp()
Get the message timestamp.
java.lang.String
getJMSType()
Get the message type.
long
getLongProperty(java.lang.String name)
Return the long property value with the given name.
java.lang.Object
getObjectProperty(java.lang.String name)
Return the Java object property value with the given name.
java.util.Enumeration
getPropertyNames()
Return an Enumeration of all the property names.
short
getShortProperty(java.lang.String name)
Return the short property value with the given name.
java.lang.String
getStringProperty(java.lang.String name)
Return the String property value with the given name.
boolean
propertyExists(java.lang.String name)
Check if a property value exists.
void
setBooleanProperty(java.lang.String name,
boolean value)
Set a boolean property value with the given name, into the Message.
void
setByteProperty(java.lang.String name,
byte value)
Set a byte property value with the given name, into the Message.
void
setDoubleProperty(java.lang.String name,
double value)
Set a double property value with the given name, into the Message.
void
setFloatProperty(java.lang.String name,
float value)
Set a float property value with the given name, into the Message.
void
setIntProperty(java.lang.String name,
int value)
Set an integer property value with the given name, into the Message.
void
setJMSCorrelationID(java.lang.String correlationID)
Set the correlation ID for the message.
void
setJMSCorrelationIDAsBytes(byte[] correlationID)
Set the correlation ID as an array of bytes for the message.
void
setJMSDeliveryMode(int deliveryMode)
Set the delivery mode for this message.
void
setJMSDestination(Destination destination)
Set the destination for this message.
void
setJMSExpiration(long expiration)
Set the message's expiration value.
void
setJMSMessageID(java.lang.String id)
Set the message ID.
void
setJMSPriority(int priority)
Set the priority for this message.
void
setJMSRedelivered(boolean redelivered)
Set to indicate whether this message is being redelivered.
void
setJMSReplyTo(Destination replyTo)
Set where a reply to this message should be sent.
void
setJMSTimestamp(long timestamp)
Set the message timestamp.
void
setJMSType(java.lang.String type)
Set the message type.
void
setLongProperty(java.lang.String name,
long value)
Set a long property value with the given name, into the Message.
void
setObjectProperty(java.lang.String name,
java.lang.Object value)
Set a Java object property value with the given name, into the Message.
void
setShortProperty(java.lang.String name,
short value)
Set a short property value with the given name, into the Message.
void
setStringProperty(java.lang.String name,
java.lang.String value)
Set a String property value with the given name, into the Message.
Field Detail
DEFAULT_DELIVERY_MODE
public static final int DEFAULT_DELIVERY_MODE
DEFAULT_PRIORITY
public static final int DEFAULT_PRIORITY
DEFAULT_TIME_TO_LIVE
public static final int DEFAULT_TIME_TO_LIVE
Method Detail
getJMSMessageID
public java.lang.String getJMSMessageID()
throws JMSException
javax.jms.Message#setJMSMessageID()
setJMSMessageID
public void setJMSMessageID(java.lang.String id)
throws JMSException
id
- the ID of the messagegetJMSMessageID()
getJMSTimestamp
public long getJMSTimestamp()
throws JMSException
javax.jms.Message#setJMSTimestamp()
setJMSTimestamp
public void setJMSTimestamp(long timestamp)
throws JMSException
timestamp
- the timestamp for this messagegetJMSTimestamp()
getJMSCorrelationIDAsBytes
public byte[] getJMSCorrelationIDAsBytes()
throws JMSException
javax.jms.Message#setJMSCorrelationID()
,
getJMSCorrelationID()
,
javax.jms.Message#setJMSCorrelationIDAsBytes()
setJMSCorrelationIDAsBytes
public void setJMSCorrelationIDAsBytes(byte[] correlationID)
throws JMSException
correlationID
- the correlation ID value as an array of bytes.javax.jms.Message#setJMSCorrelationID()
,
getJMSCorrelationID()
,
getJMSCorrelationIDAsBytes()
setJMSCorrelationID
public void setJMSCorrelationID(java.lang.String correlationID)
throws JMSException
correlationID
- the message ID of a message being referred to.getJMSCorrelationID()
,
getJMSCorrelationIDAsBytes()
,
javax.jms.Message#setJMSCorrelationIDAsBytes()
getJMSCorrelationID
public java.lang.String getJMSCorrelationID()
throws JMSException
javax.jms.Message#setJMSCorrelationID()
,
getJMSCorrelationIDAsBytes()
,
javax.jms.Message#setJMSCorrelationIDAsBytes()
getJMSReplyTo
public Destination getJMSReplyTo()
throws JMSException
javax.jms.Message#setJMSReplyTo()
setJMSReplyTo
public void setJMSReplyTo(Destination replyTo)
throws JMSException
replyTo
- where to send a response to this messagegetJMSReplyTo()
getJMSDestination
public Destination getJMSDestination()
throws JMSException
javax.jms.Message#setJMSDestination()
setJMSDestination
public void setJMSDestination(Destination destination)
throws JMSException
destination
- the destination for this message.getJMSDestination()
getJMSDeliveryMode
public int getJMSDeliveryMode()
throws JMSException
javax.jms.Message#setJMSDeliveryMode()
,
DeliveryMode
setJMSDeliveryMode
public void setJMSDeliveryMode(int deliveryMode)
throws JMSException
deliveryMode
- the delivery mode for this message.getJMSDeliveryMode()
,
DeliveryMode
getJMSRedelivered
public boolean getJMSRedelivered()
throws JMSException
javax.jms.Message#setJMSRedelivered()
setJMSRedelivered
public void setJMSRedelivered(boolean redelivered)
throws JMSException
redelivered
- an indication of whether this message is being
redelivered.getJMSRedelivered()
getJMSType
public java.lang.String getJMSType()
throws JMSException
javax.jms.Message#setJMSType()
setJMSType
public void setJMSType(java.lang.String type)
throws JMSException
type
- the class of messagegetJMSType()
getJMSExpiration
public long getJMSExpiration()
throws JMSException
javax.jms.Message#setJMSExpiration()
setJMSExpiration
public void setJMSExpiration(long expiration)
throws JMSException
expiration
- the message's expiration timegetJMSExpiration()
getJMSPriority
public int getJMSPriority()
throws JMSException
javax.jms.Message#setJMSPriority()
setJMSPriority
public void setJMSPriority(int priority)
throws JMSException
priority
- the priority of this messagegetJMSPriority()
clearProperties
public void clearProperties()
throws JMSException
propertyExists
public boolean propertyExists(java.lang.String name)
throws JMSException
name
- the name of the property to test
getBooleanProperty
public boolean getBooleanProperty(java.lang.String name)
throws JMSException
name
- the name of the boolean property
getByteProperty
public byte getByteProperty(java.lang.String name)
throws JMSException
name
- the name of the byte property
getShortProperty
public short getShortProperty(java.lang.String name)
throws JMSException
name
- the name of the short property
getIntProperty
public int getIntProperty(java.lang.String name)
throws JMSException
name
- the name of the integer property
getLongProperty
public long getLongProperty(java.lang.String name)
throws JMSException
name
- the name of the long property
getFloatProperty
public float getFloatProperty(java.lang.String name)
throws JMSException
name
- the name of the float property
getDoubleProperty
public double getDoubleProperty(java.lang.String name)
throws JMSException
name
- the name of the double property
getStringProperty
public java.lang.String getStringProperty(java.lang.String name)
throws JMSException
name
- the name of the String property
getObjectProperty
public java.lang.Object getObjectProperty(java.lang.String name)
throws JMSException
setObject
method call, or it's equivalent
primitive set
name
- the name of the Java object property
getPropertyNames
public java.util.Enumeration getPropertyNames()
throws JMSException
setBooleanProperty
public void setBooleanProperty(java.lang.String name,
boolean value)
throws JMSException
name
- the name of the boolean propertyvalue
- the boolean property value to set in the Message.
setByteProperty
public void setByteProperty(java.lang.String name,
byte value)
throws JMSException
name
- the name of the byte propertyvalue
- the byte property value to set in the Message.
setShortProperty
public void setShortProperty(java.lang.String name,
short value)
throws JMSException
name
- the name of the short propertyvalue
- the short property value to set in the Message.
setIntProperty
public void setIntProperty(java.lang.String name,
int value)
throws JMSException
name
- the name of the integer propertyvalue
- the integer property value to set in the Message.
setLongProperty
public void setLongProperty(java.lang.String name,
long value)
throws JMSException
name
- the name of the long propertyvalue
- the long property value to set in the Message.
setFloatProperty
public void setFloatProperty(java.lang.String name,
float value)
throws JMSException
name
- the name of the float propertyvalue
- the float property value to set in the Message.
setDoubleProperty
public void setDoubleProperty(java.lang.String name,
double value)
throws JMSException
name
- the name of the double propertyvalue
- the double property value to set in the Message.
setStringProperty
public void setStringProperty(java.lang.String name,
java.lang.String value)
throws JMSException
name
- the name of the String propertyvalue
- the String property value to set in the Message.
setObjectProperty
public void setObjectProperty(java.lang.String name,
java.lang.Object value)
throws JMSException
name
- the name of the Java object property.value
- the Java object property value to set in the Message.
acknowledge
public void acknowledge()
throws JMSException
clearBody
public void clearBody()
throws JMSException
Package
Class
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD