Why and when to pass the JMS message payload by reference
當傳送大型物件訊息或位元組訊息時,為了序列化、解除序列化及複製訊息有效負載,可能會耗用大量的記憶體和處理器成本。 如果您在 Connection Factory 或啟動規格上啟用 pass message payload by reference 內容,您會通知預設傳訊提供者置換 JMS 1.1 規格,這項資料的複製有可能會縮減或略過。
Background
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.
- The parts of the JMS specification that are bypassed by these properties are defined to ensure message data integrity.
- Any of your JMS applications that use these properties must strictly follow the rules that are described in detail later in this section, or you risk losing data integrity.
- You should read and understand this entire topic before enabling these properties.
- producerDoesNotModifyPayloadAfterSet (Connection Factory) 或 forwarderDoesNotModifyPayloadAfterSet(啟動規格)
- 當啟用這個內容時,Connection Factory 所產生或啟動規格所轉遞的物件或位元組訊息倘若設在訊息中,就不會進行複製,只有在絕對必要之時,才會序列化。 傳送這些訊息的應用程式,在訊息內設定了資料之後,便無法修改資料。
- consumerDoesNotModifyPayloadAfterGet
- 當啟用這個內容時,只有在絕對必要之時,才會將透過 Connection Factory 或啟動規格收到的物件訊息序列化。 應用程式不能修改從這些訊息取得的資料。
Potential benefits of passing the message payload by reference
- Your JMS applications conform to the rules described in the next section of this topic.
- Your message producer and consumer applications run in the same JVM (server), along with the messaging engine that hosts the destination used by these applications.
- If your applications run in different servers, or on the z/OS® platform (where WebSphere Application Server runs in multiple JVMs), then object messages are serialized and no performance benefits are gained for these messages. Bytes message benefits might still be gained.
- There are many internal runtime conditions that can cause your messages to be serialized, so even if your configuration meets all the conditions described in this topic you might gain little or no performance benefit from enabling the "pass message payload by reference" properties.
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. |
Rules that your JMS applications must obey
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: JMS 轉遞應用程式會接收訊息(透過 Connection Factory,如果是訊息驅動 Bean,則透過啟動規格),然後將訊息物件傳送到另一個目的地。
|
A JMS forwarder application that replaces
the payload of the received message with a new payload:
|
Ensuring that your object messages can be serialized
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.
- CWSIK0200E: An object of class "{0}" has been set into the message payload but it cannot be serialized.
- Explanation: An object message sent with the producerDoesNotModifyPayloadAfterSet flag enabled on its connection factory was sent with a payload that was not serializable by the system. This message data has been lost.
- Action: Disable the producerDoesNotModifyPayloadAfterSet on the connection factory. Without the flag enabled, the JMS application that sets the object into the message will receive any serialization exception immediately.
- JMS_IBM_ExceptionReason
- SIRCConstants.SIRC0200_OBJECT_FAILED_TO_SERIALIZE
- JMS_IBM_ExceptionTimestamp
- The time at which the object failed to serialize, in System.currentTimeMillis() form.
- JMS_IBM_ExceptionMessage
- Message CWSIK0200E, as previously described.
- SI_ExceptionReason
- SIRC0200_OBJECT_FAILED_TO_SERIALIZE
- SI_ExceptionTimestamp
- The time at which the object failed to serialize, in System.currentTimeMillis() form.
- SI_ExceptionInserts
- A string array containing one entry. The entry contains the class name of the object.