Using an Inbox and Outbox for messages
We have now updated the Depot
module so that we can work with a single database connection and transaction. We want to now use that to make our database interactions and message publishing atomic.
When we make the publishing and handling of the messages atomic alongside the other changes that are saved into our database, we gain the following benefits:
- Idempotent message processing: We can be sure that the message that we are processing will only be processed a single time
- No application state fragmentation: When state changes occur in our application, they will be saved as a single unit or not at all
With the majority of the work behind us to set up the transactions, we can now implement the inboxes and outboxes for our messages.
Implementing a messages inbox
Back in Chapter 6, in the Idempotent message delivery section, I presented a way in which we could ensure that no matter how many times a message was received...