I’m bit new to CQRS pattern and fed up with traditional CRUD approach. Need to know if whatever I’m trying fits into CQRS pattern and secondly, the implementation of the same using Axon framework.
Below is the scenario,
I’m trying to implement shopping cart model where multiple users can in parallel query their items present in cart and checkout whereas the update/add would be less accounted. Need to know if this component would really fit into CQRS terminology.
As per the docs for getting started, This was the flow that I came up with,
Client --> initiate AddItemtoCart command --> command bus --> command handler (Validate structure/business) --> Event trigger --> Event bus --> Event handler --> Write database
It did work well with standalone but mixing the same with REST API led me to confused state.
Client POST request --> API --> Initate command --> Command bus --> command handler --> Event trigger --> Event bus --> Event handler
By this way, the command handler can respond in ‘fire and forget style’ but I require the added item as response to the client with synchronous event handling to ensure consistency.(Since CRUD works so with REST). I need to know how to do this either synchronous/asynchronous using Axon ?
Exploring on forums, got some working mechanisms. Command handler can respond back with exception/response using callbacks and even Spring async context within command handler scope. But what I’m looking is the response back to client after event being handled. Correct me if am wrong in expecting this with CQRS approach.
Whatever i understood till now is that, I need to have separate Commands and query handling mechanism. Below are approaches that i found while exploring in terms of REST response,
approach#1: If the command does the event sourcing asynchronously, respond back to the client with HTTP 202 Accepted response including url to check the status of asynchronous handled event.
Poll the URL to know if the status has updated and once it is green, query the items in the cart and show it in UI. (multiple http calls as a whole, traditionally one would suffice)
approach#2: Use websocket or such to push the response from the server to client async but need to know how to the implement it with axon framework ?
approach#3: After the event has been handled, publish the message to MQ and client should pick that. Got it logically but need to know if it will create a listener inside the command handler side and wait for event response MQ ?
May be u guys can help me out in understanding Axon better.
Sivarajan R P