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:

  1. Find the book Camel in Action, 2nd Edition.
  2. Put the book into the basket.
  3. Maybe continue shopping and look for other books.
  4. Go to the checkout.
  5. Enter shipping and credit card details.
  6. Confirm the purchase.
  7. Wait for the confirmation.
  8. 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.

12.1 Why use transactions?

12.1.1 The Rider Auto Parts partner integration application

12.1.2 Setting up the JMS broker and the database

12.1.3 The story of the lost message

12.2 Transaction basics

12.2.1 Understanding Spring’s transaction support

12.2.2 Adding transactions

12.2.3 Testing transactions

12.3 The Transactional Client EIP

12.3.1 Using local transactions

12.3.2 Using global transactions

12.3.3 Transaction starting from a database resource

12.3.4 Transaction redeliveries

12.3.5 Using different transaction propagations

12.3.6 Returning a custom response when a transaction fails

12.4 Compensating for unsupported transactions

12.4.1 Introducing UnitOfWork

12.4.2 Using synchronization callbacks

12.4.3 Using onCompletion

12.5 Idempotency

12.5.1 Idempotent Consumer EIP

12.5.2 Idempotent repositories

sitemap