When large object messages or bytes messages are sent, the cost in memory and processor use of serializing, deserializing, and copying the message payload can be significant. If you enable the pass message payload by reference properties on a connection factory or activation specification, you tell the default messaging provider to override the JMS 1.1 specification and potentially reduce or bypass this data copying.
The JMS 1.1 specification states that object messages are passed by value. This means that a JMS provider such as the default messaging provider in WebSphere® Application Server has to take a copy of the object in ObjectMessage at the time the object is set into the message payload, in case the client application modifies the object after setting it. In practice this means serializing it, as there is no other entirely safe way to take a copy. The specification also states that when a consumer application gets the data from the message, the JMS provider must create and return a copy of that data.
If you enable the "pass message payload by reference" properties, you might get memory and performance improvements for JMS messaging.
Degree of potential performance benefit | Configuration and runtime events | When the data is copied |
---|---|---|
No potential benefit |
The "pass message payload by reference" properties are not enabled (default behavior). |
Object message data is copied as soon as it is set into the message and when it is retrieved from the message. Bytes message data is copied as soon as it is set into the message and when it is retrieved from the message. |
Some potential benefit |
The "pass message payload by reference" properties
are enabled, and either or both of the following conditions are true:
|
Bytes message data is only copied when necessary. |
Maximum potential benefit |
The "pass message payload by reference" properties
are enabled, and both of the following conditions are true:
|
Bytes message data is only copied when necessary. |
The parts of the JMS specification that are bypassed by the "pass message payload by reference" properties are defined to ensure message data integrity. If your JMS applications obey the rules given in the following table, then you can safely enable the "pass message payload by reference" properties on the connection factories and activation specifications that the applications use.
If you enable the "pass message payload by reference" properties for JMS applications that do not follow these rules, then the applications might receive exceptions or, more importantly, the integrity of the message data might be compromised.
Application type | Rules |
---|---|
JMS producer application |
A JMS producer application that sends object messages must not alter the object after it is set into the payload of the message. A JMS producer application that sends bytes
messages:
|
JMS consumer application |
A JMS consumer application that receives object messages must not alter the payload it gets from the message. |
JMS forwarder application Note:
A JMS forwarder application receives a message (through a connection factory, or if it is a message-driven bean through an activation specification), then sends the message object on to another destination.
|
A JMS forwarder application that replaces
the payload of the received message with a new payload:
|
Under normal JMS messaging conditions (that is, when the "pass message payload by reference" properties are not enabled), the data in an object message is serialized as soon as the object is passed to the messaging system, for example on set or send. If the message payload cannot be serialized, then an exception message is immediately returned to the client application.
When the "pass message payload by reference" properties are enabled, the message payload is accepted from the client application without attempting to serialize it. If the system later discovers that the data cannot be serialized, the system can no longer inform the client application that sent the message - and because the data is not serializable, the system cannot persist or transmit the complete message. The message and its properties are stored, but the user data inside the message (the payload) cannot be stored and is discarded. If there are serialization problems when the system tries to convert an object message into a data graph for a mediation, the message payload is discarded and the mediation receives a message with the data value set to null.
If your data cannot be serialized, then it is lost. Therefore you should first test your configuration without enabling the "pass message payload by reference" properties, to check that all data sent into the system is serializable.