4.8. Using Transactions in Python

This section shows how to use local server transactions, which buffer published messages and acknowledgements and process them upon commit, guaranteeing that they will all succeed or fail as a unit. You can easily do this by making the session transactional. Once you do this, all message transfers and acknowledgements are queued until a commit or rollback is done on the session. After a commit or rollback, the session remains transactional, so operations continue to be queued until the next commit or rollback.
To make a session transactional, call tx_select():
To commit all operations pending on a transactional session, call tx_commit():
To roll back all operations pending on a transactional session, call tx_rollback():
Transactions are used primarily to ensure that delivery is kept consistent in a messaging system. For instance, if you want to make sure that messages are properly forwarded, you can make a session transactional, subscribe to one queue, and publish received messages to another queue, acknowledging the initial delivery and doing a commit. If you do this, the publish and consume are atomic, and will both succeed or fail as a unit.