Event Processing Flow Changes from Axon 3 to Axon 4

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.

  1. 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.

  2. 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).

  3. Meanwhile, the controller that originally sent the command (sendAndWait), immediately afterwards attempts to access data in the “views”.

  4. 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!

Hi @Drew,

Axon 3 is also before my time but one of the things that changed was the default Event Processor it is used!
On Axon 3, subscribing was the default while on Axon 4, tracking is the default.
Can you try to set your event processor to subscribing and see if you get the same behaviour as before?

You can read a lot more about it here as I am not going into details here :slight_smile:

I know you mentioned you don’t want to change this pattern but that would be my first recommendation :wink:
If you are interested, this kind of behaviour can be achieved using Subscription Queries and we made a code-samples here. Have a look, maybe this is something feasible for you at this moment as well!


Hi Lucas,

You are a lifesaver! That seems to have fixed it. Appreciate the help - at least this way we can get to Axon4, and hopefully someday get to fixing our patterns :smile:

Thanks so much!

1 Like

Glad to help @Drew!

And hope to see you around more often =)