|
SonicMQ API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Message
An Implementation of JMS Message.
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
| AND | T | F | U +------+-------+-------+------- | T | T | F | U | F | F | F | F | U | U | F | U +------+-------+-------+-------
The definition of the OR operator
| OR | T | F | U +------+-------+-------+-------- | T | T | T | T | F | T | F | U | U | T | U | U +------+-------+-------+-------
The definition of the NOT operator
| NOT +------+------ | T | F | F | T | U | U +------+-------
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.
Message
,
BytesMessage
,
MapMessage
,
ObjectMessage
,
StreamMessage
,
TextMessage
Field Summary |
---|
Fields inherited from interface javax.jms.Message |
---|
DEFAULT_DELIVERY_MODE, DEFAULT_PRIORITY, DEFAULT_TIME_TO_LIVE |
Method Summary | |
---|---|
void |
acknowledgeAndForward(Destination destination)
A SonicMQ extension - acknowledge this message and forward it to a new destination. |
void |
acknowledgeAndForward(Destination destination,
int deliveryMode,
int priority,
long timeToLive)
A SonicMQ extension - acknowledge this message and forward it to a new destination. |
int |
getBodySize()
Return the size of the Message body. |
Channel |
getChannel()
Retrieve the channel attached to this message. |
Destination |
getDestinationProperty(java.lang.String name)
Return the value of the javax.jms.Destination property with the specified name. |
java.util.Hashtable |
getProperties()
Get message properties. |
boolean |
hasChannel()
Return true if this message has a channel attached. |
boolean |
isDestinationProperty(java.lang.String name)
Indicates whether a property is a javax.jms.Destination property. |
void |
setChannel(Channel channel)
Add the given channel to the message. |
void |
setChannel(Message message)
Add the channel associated with the given message to this channel. |
void |
setDestinationProperty(java.lang.String name,
Destination value)
Set a javax.jms.Destination property value with the specified name into the Message. |
Method Detail |
---|
void acknowledgeAndForward(Destination destination, int deliveryMode, int priority, long timeToLive) throws JMSException
This method can be called only on messages that were received in a progress.message.jclient.Session.SINGLE_MESSAGE_ACKNOWLEDGE session. The acknowledgment and the move to the new destination are performed as an atomic operation - SonicMQ guarantees that either both succeed or both fail. Other messages that might have been received before this message, through the same session, are not affected. acknowledgeAndForward can be only if the message was not yet acknowledged.
acknowledgeAndForward should be used for better performance - similar functionality can be achieved by acknowledging the message and then sending it to the new destination in a transacted session - but acknowledgeAndForward is more efficient.
acknowledgeAndForward is currently supported only by messages that were received from a queue destination and are forwarded to a queue.
destination
- The new destination (queue only) of this message.deliveryMode
- the delivery mode to use.priority
- the priority for this message.timeToLive
- the message's lifetime (in milliseconds).
InvalidDestinationException
- if this destination is not a valid queue.
JMSSecurityException
- if this client doesn't have permission to send to the new queue destination.
java.lang.IllegalStateException
- if this message was not received through a SINGLE_MESSAGE_ACKNOWLEDGE session
or was already acknowledged.
JMSException
- if JMS fails to acknowledge and forward the message due to some internal error.void acknowledgeAndForward(Destination destination) throws JMSException
This method can be called only on messages that were received in a progress.message.jclient.Session.SINGLE_MESSAGE_ACKNOWLEDGE session. The acknowledgment and the move to the new destination are performed as an atomic operation - SonicMQ guarantees that either both succeed or both fail. Other messages that might have been received before this message, through the same session, are not affected. acknowledgeAndForward can be only if the message was not yet acknowledged.
acknowledgeAndForward should be used for better performance - similar functionality can be achieved by acknowledging the message and then sending it to the new destination in a transacted session - but acknowledgeAndForward is more efficient.
acknowledgeAndForward is currently supported only by messages that were received from a queue destination and are forwarded to a queue.
The delivery parameters - JMSDeliveryMode, JMSPriority and JMSTimeToLive of this message are used by default for forwarding it to the new destination.
destination
- The new destination (queue only) of this message.
InvalidDestinationException
- if this destination is not a valid queue.
JMSSecurityException
- if this client doesn't have permission to send to the new queue destination.
java.lang.IllegalStateException
- if this message was not received through a SINGLE_MESSAGE_ACKNOWLEDGE session
or was already acknowledged.
JMSException
- if JMS fails to acknowledge and forward the message due to some internal error.Channel getChannel() throws JMSException
JMSException
void setChannel(Channel channel) throws JMSException
JMSException
void setChannel(Message message) throws JMSException
You will receive an javax.jms.IllegalStateException if you attempt to set a channel on a message that already has a channel, you attempt to set an active channel onto another message, or the message does not already have a channel.
This method is useful if you wish to forward a message with a channel to another location using a different message other than the one you received it on.
message
- The Message to retrieve the channel from.
JMSException
- If there is an internal JMS error.boolean hasChannel() throws JMSException
JMSException
int getBodySize() throws JMSException
JMSException
java.util.Hashtable getProperties()
boolean isDestinationProperty(java.lang.String name)
name
- the name of the property to test
Destination getDestinationProperty(java.lang.String name) throws JMSException
name
- the name of the Destination property
JMSException
- if JMS fails to get Property due to
some internal JMS error.
MessageFormatException
- if this type conversion is invalid.void setDestinationProperty(java.lang.String name, Destination value) throws JMSException
name
- the name of the javax.jms.Destination propertyvalue
- the javax.jms.Destination property value to set in the Message.
JMSException
- if JMS fails to set Property due to
some internal JMS error.
MessageNotWriteableException
- if properties are read-only
|
SonicMQ API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |