I have two types of events :
- PersonChanged
- PersonAddressChanged.
Both of them are being published also when a new Person (and a new address) is created (kind of create or update).
When a new person is created two events are published: PersonChanged and PersonAddressChanged (in that order). However, because NServiceBus
is asynchronous they can be handled in any order. And when an address is changed (for an existing person) there is no PersonChanged event, only PersonAddressChanged event.
I want to write a handler for PersonAddressChanged event which will :
- Check if the person is in database
- If yes then just make an update
- If no then start saga and wait for PersonChanged event (assuming it is a new person)
And in PersonChanged event I need to insert the person to database, find the saga and run the handler for PersonAddressChanged once again.
Can I achieve this with NServiceBus Sagas? I cannot assume that the message processing should be in order PersonChanged → PersonAddressChanged
because sometimes there will be no PersonChanged event for any particular address change.