12 Transactions and idempotency
This chapter covers
- Understanding why you need transactions
- Using and configuring transactions
- Understanding the differences between local and global transactions
- Using transactions with messaging and databases
- Rolling back transactions
- Compensating when transactions aren’t supported
- Preventing duplicate messages by using idempotency
- Learning about the idempotent repository implementations shipped out of the box
To help explain transactions, let’s look at an example from real life. You may well have ordered this book from Manning’s online bookstore, and if you did, you likely followed these steps:
- Find the book Camel in Action, 2nd Edition.
- Put the book into the basket.
- Maybe continue shopping and look for other books.
- Go to the checkout.
- Enter shipping and credit card details.
- Confirm the purchase.
- Wait for the confirmation.
- Leave the web store.
What seems like an everyday scenario is a fairly complex series of events. You have to put books in the basket before you can check out; you must fill in the shipping and credit card details before you can confirm the purchase; if your credit card is declined, the purchase won’t be confirmed; and so on. The ultimate resolution of this transaction is one of two states: either the purchase is accepted and confirmed, or the purchase is declined, leaving your credit card balance uncharged.