Force axon to wait until the command handling completes

Skip to first unread message

Rohit Singh

Sep 24, 2020, 7:03:02 AM9/24/20
to Axon Framework Users
In my spring-boot project i have 2 separate services for command and query. Both services are connected to axon and sharing the same database.

My ui is designed in such a way that, when user submits the form to create some data, the ajax makes calls to command-service in order to save the data in database and upon a succesful save it immediately calls to query-service in order to fetch the saved data.

The probelm here is the query-service is not always able to get the newly created data  as it is querying the database before the command-service finishes it's execution(creating data in databse). 

I think the solution here is to  make    org.axonframework.commandhandling.gateway.CommandGateway.sendAndWait(Object)   wait untill the command-handling complets, so that the ajax will call query-serivce only after the command-service completes.

Can someone please suggest whether it is achievable or not ? if yes then how to achieve this.

Steven van Beelen

Sep 24, 2020, 9:11:10 AM9/24/20
to Axon Framework Users
Hi Rohit,

The sendAndWait operation will not save you here, as it will still make the command handling and event handling process two distinct threads when using the Tracking Event Processor.
It is simpler, as I pointed out in this other post you've started, to embrace the fact you are going to be eventually consistent in such a distributed environment.
So note that all what sendAndWait does is wait until the handling of the command and publication of the events is finalized.

And again, know that the mailing list will be discontinued as of next week Monday.
Please move any questions you might have in the future to instead.

Trusting this clarifies things.


❗ Please note that this mailing list will be discontinued on September 28 ❗
We are moving to and we do hope you'll join us there.
For more details please see
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages