Force axon to wait until the command handling completes

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.

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.