Completing or Canceling Transactions

Messages that are published and received on a transaction are staged on the Solace PubSub+ event broker. The transaction can either be:

Committing Transactions

When a commit() is successfully invoked for a transaction, the following occurs:

  • for publish operations, the staged messages are sent to their destinations
  • for receive operations, the received messages are acknowledged by the consumers and then removed from the endpoints they were spooled to

Commits are blocking operations. After these actions, the transaction is completed, and the next transaction automatically begins.

If a commit fails for any reason, a rollback of the entire transaction occurs, and a TransactionRolledBackException is thrown to indicate the failure cause.

Rolling Back Transactions

Instead of completing an active transaction through a commit, a client application can call rollback() to rollback the transaction. When a rollback is performed, the following occurs:

  • staging information for the active transaction is removed, so that:
    • for publish operations, the published messages are deleted
    • for consume operations, messages remain on the endpoints they were spooled to
  • a new transaction is automatically generated

Rollbacks are blocking operations.

If a transacted Session fails due to a network failure or an event broker reset, the client can immediately reconnect (this is automatic if the number of reconnect retries for the client connection is greater than zero), and, if possible, the API reestablishes the transaction that was in progress. If the Session and transaction are not reestablished within three minutes, the event broker automatically rolls back the transaction that was in progress. (For information on setting client reconnect properties, refer to Configuring Connection Time-Outs and Retries.)

Closing Transacted Sessions

To cleanly terminate a transacted Session, the client application should commit the current transaction, and then call close() to close the transacted Session.

If a client application closes a transacted Session without first committing the current transaction, the API rolls back that transaction, and it does not automatically reattempt the transaction.