Read models are updated before event handlers that implement ISubscribeSynchronousToAll #877
-
We publish all events to event grid using a custom class that implements ISubscribeSynchronousToAll. I have noticed during testing that the event is not published to event grid until the read models that subscribe to that event have been updated. Could someone confirm that this is the expected behaviour? When an aggregate emits an event, is the event handled in a synchronous manner in a pre-defined order? For example, is it something like this:
I'm a bit confused because I had assumed that the subscribers (read model and event grid) would run in parallel. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Inspecting the source code I think 1. and 2. are backwards in your list
|
Beta Was this translation helpful? Give feedback.
-
Did the above answer your question @alasdair-stark-screenmedia? In short, all read models are updated before subscribers as subscribers may rely on read models being updated to reflect the event just emitted. The implantation of EventFlow splits everything into small well defined classes with interfaces that allows you to replace any functionality that doesn't fit your need. The specific class you are looking to replace, is the |
Beta Was this translation helpful? Give feedback.
Inspecting the source code I think 1. and 2. are backwards in your list
AggregateRoot.Emit()
triggers application of the event to the aggregate state when it first emits. Then execution result is returned back where theAggregateStore.UpdateAsync()
commits the events to the store then triggersDomainEventPublisher.PublishAsync()
, which FIRST updates applicable read models and then dispatches to subscribers (Subscribers of ALL events first, then Sync subscribers, then Async Subscribers, then Sagas). If exceptions are thrown along that publishing path then execution stops. So if Read Models throw exceptions then subscribers aren't dispatched to. If SubcribersOfAllEvents results in an except…