I am looking to set up a basic DDD model using a couple of different techniques on the Domain models. Communication between the domain models is important and I would intend to use domain events for this.
One part I am struggling with currently is the robust implementation of the domain events. For example, we have domains in separate bounded contexts:
The new order process is completed within the order domain and an event
NewOrderReceived is emitted. At this point, the inventory domain must pick up this event and initiate a
Assuming everything runs OK then this is quite simple, but what happens if an exception is thrown either during the event emit or in the event recieve.
There could eventually be multiple other domains picking up events so I think the best course of action here would be to queue and run then asynchronously. However, in this case, there is no feedback to the process emitting the event as to whether the listeners were successful. If they fail first time then what would the retry/error handling mechanism look like? For example, An order was created with product x, but actually that product does not exist/could not be found by the inventory domain.
Similarly, there would be some events that need to go both ways. For example, an
OrderCancellationWasRequested event is fired by the order domain. The inventory domain would have to both acknowledge, act and then respond with a success/fail. In this case, we actually want to catch the response like in a REST API, but using domain events.
For reference, here are some useful resources that have helped me with the overall ideas and some implementation so far: