Publishing Messages in Transactions

To publish messages in a transaction, a MessageProducer must be acquired from the transacted Session. To then publish messages in transactions, call MessageProducer.send(...).

In a transaction, the event broker stages the published messages, and they are not delivered to their destinations on the event broker until the client issues a commit. If the commit is successful, the messages are delivered to their destinations and the staging information is removed.

How the Behavior of Endpoint Message Discard Affects Transactions

When a message that was published in a transaction cannot be spooled successfully to any of its destination endpoints on a commit, the message is discarded. In this case, the endpoint's reject-msg-to-sender-on-discard property determines how the endpoint handles the discarded message.

  • If the reject-msg-to-sender-on-discard property for the endpoint is enabled, a client commit response is returned to the client, the message is discarded, and the commit fails. In this case, the message cannot be spooled to other endpoints that it may have been destined for.
  • If the reject-msg-to-sender-on-discard property for the endpoint is not enabled, the message is "silently" discarded (that is, the endpoint discards the message but returns a commit success response to the client), and the commit completes. In this case, the message can be spooled to other endpoints that it may have been destined for.

When provisioning a Queue, by default the reject-msg-to-sender-on-discard property is enabled; when provisioning a Topic Endpoint, by default the property is not enabled.

For more information on the reject-msg-to-sender-on-discard endpoint property and the conditions that can cause an endpoint not to spool and then to discard a message, see: