I'm new to NServiceBus and trying to find the best way to model a scenario which uses compensating transactions.
For example, say I have a typical BookHotel scenario:
In the happy case, the messaging flow would proceed as follows:
- BookHotelCommand --> BookHotelSaga
- BookFlightCommand --> Reply IFlightBookedMessage
- BookRentalCommand --> Reply IRentalBookedMessage
- ReplyToOriginator --> HotelBookedMessage
How would I model compensating transactions in the above flow? I was initially thinking of calling a "UnbookHotelSaga" in one of the replies above, based on some business conditions. However, I seem to be running into some challenges with getting this working. Can someone with Saga experience comment if this is the right approach.
Here is the scenario I was thinking would work by calling another Saga:
- BookHotelCommand --> BookHotelSaga
- BookFlightCommand --> Reply IFlightBookedMessage
- BookRentalCommand --> (condition satisfied) --> UnbookHotelCommand --> UnbookHotelSaga
- UnbookRentalCommand --> Reply IUnbookRentalMessage
- UnbookFlightCommand --> Reply IUnbookFlightMessage
- UnbookHotelCommand --> ReplyToOriginator --> UnbookedHotelMessage
Can someone please advise on the best-practices approach to implementing compensating transactions?