Hi all,
I am in the middle of a proof-of-concept upgrade for a service from Axon 3.0.6 to 4.4.5, and noticed something interesting with the event processing flow in the following scenario.
-
The service I am upgrading has a controller that sends a command to create an aggregate. The aggregate then applies a lifecycle event, which is afterwards published onto the event bus.
-
A non-aggregate listener for this lifecycle event then creates a “view” of the aggregate (basic Postgres DTO representing the current state of the aggregate).
-
Meanwhile, the controller that originally sent the command (
sendAndWait
), immediately afterwards attempts to access data in the “views”. -
In both Axon3 and Axon4, the
sendAndWait
finishes as soon as the aggregate finishes applying the lifecycle event. Since this is before the non-aggregate listener even receives the event, the controller is not able to find the view. Approximately one second later, the view is created.
Interestingly, adding spring.jpa.open-session-in-view=false
fixed this issue for Axon3 (the service uses a Postgres data store). Immediately after the sendAndWait
returned, the controller was able to retrieve the view.
The Axon3 upgrade was before my time, but I believe it was related to Spring not committing the transaction before Axon’s transaction (UOW) completed.
Unfortunately, with Axon4 the service can no longer retrieve the data from the views immediately after the sendAndWait
. I’ve gone through a lot of documentation, and have not been able to find any changes that would have caused this.
I realize this breaks Axon’s model of eventual consistency; unfortunately, this is just one of many services using this pattern and it’s not feasible to redesign. We also have a substantial number of axon events in these services, so we’d like to avoid implementing the Query
models as well.
Any ideas on why the OSIV property change would have worked for Axon3 and not Axon4? Or is this related to a separate change altogether? I’d appreciate any help; despite the amazing Axon documentation I haven’t had much luck figuring this out.
Thanks so much!
-Drew