We’ve recently went through the process of updating our ~20 NSB Handlers to version 6. With that, we wanted to remove our dependency on DTC so we also made the switch to enable outbox,as well as moved from NHibernate Persistence to SQL Persistence. We noticed an issue though where partial updates began happening.
For example, we handle a message that performs an update to our Application DB, when it’s finished it also publishes another message to be consumed by another handler. What we were seeing is only after enabling outbox, when the handler handles the message, the database transaction would commit immediately before the successful completion of the handler. If the handler failed somewhere else, the messages would not be sent though. My understanding was the entire handler would enlist in the Outbox transaction scope, not just the message sending/publishing.
When turning outbox off, I was able to see that the entire transaction (DB updates and message publishing) were enlisted together and if it failed, everything would be rolled back, as expected.
In order to keep Outbox enabled and wrap our handlers in a transaction again, we enabled UnitOfWork on the endpoint configuration and set WrapHandlersInTransactionScope. I know this isn’t the intended use of this functionality, but it did the trick for now.
- The business data and the outbox data are under the same connection string
- The Transport database is in a separate database with a different connection string
- Is the behavior I’m describing above the correct behavior? If so, what is the best way to go about wrapping my handlers in a transaction to avoid partial updates?
- If that is not the designed behavior, will our current “fix” of enabling WrapAllHandlersInATransactionScope suffice for now?
I’m happy to provide as much additional information as I can.