The JMS 1.1 API defines how a JMS message object is created using one of the following methods on a Session:
The following question has been raised:
Can a message be sent using a MessageProducer that was created from a different Session than was used to create the message?
This is not stated explicitly in the specification, and discussions within the JSR 343 Expert group show that different individuals have come to different conclusions on this issue.
My own interpretation is that a MessageProducer must be able to send a javax.JMS.Message irrespective of how it was created. It might have been created using Session.createMessage(), or it may have been received by a MessageConsumer.
Section 4.4.5 "Optimized message implementations" of the JMS 1.1 specification states:
A session provides message create methods that use provider-optimized implementations. This allows a provider to minimize its overhead for handling messages.
Sessions must be capable of sending all JMS messages regardless of how they may be implemented.
Furthermore, Section 3.12 of the JMS 1.1 specification states explicitly that a MessageProducer must be able to send a message that was created using a different JMS provider, and which would therefore have used a different session:
A provider must be prepared to accept, from a client, a message whose implementation is not one of its own. A message with a 'foreign' implementation may not be handled as efficiently as a provider's own implementation; however, it must be handled.
Despite this, there is a widespread view within the JMS community that for messages created within the same JVM by the same JMS provider, the session used to create the message must be the same as that used to send it.
It is therefore proposed that the JMS specification be clarified that there is no such restriction, and that a MessageProducer can be used to send any message object
- irrespective of which session or connection was used to create it,
- irrespective of whether the message was created within this JVM or received from a JMS destination, and
- irrespective of whether the MessageProducer and message are implemented by the same or different JMS providers.