Command & query CQRS

I am new to axon f/w & have very basic question which I am unable to understand.

  1. If i have to make a micro service that provides functionality to add a product & retrieve product. Would there be complete different folders for command side and query side? Also would command side and query side be sharing anything ?

  2. I have seen lot of code available on net.
    In command handler we are just calling apply method… that will create and event and further publish… but where we are actually saving data in Database like if i update description of product or price… We are not calling any method to save data in database.

@CommandHandler
public ProductAggregate(AddProductCommand command) {

apply(new ProductAddedEvent(command.getId(), command.getName()));
} 3. On command side we have aggregate, command , command handler, events… but on query side What all we need to have. Could someone please help… I know these are too basic questions but i am too confused to move on further. Any information would be really appreciated. Thanks,

Hi Rajni,

It’s fine to ask basic questions, that’s what the group is for too!

  1. Lets say at some point you want strongly type identifier classes (which definitely is a good thing), like ProductId. Your commands/events would definitely be sharing that ProductId class.
    Apart from that, I’m currently in the habit of having a folder per aggregate/entity for commands and events (more specifically, one Kotlin file for commands and one for events).
    To make it span separate services, you could think of having a separate module containing the commands/events which is used by both, if you want the services to be coupled directly that is.
    If you want both services to not be aware of each others command/event specifics, an anti-corruption/translation layer makes sense.

  2. The AggregateLifeCycle.apply() function will append your event to the event store too, in the prepare commit phase of the UnitOfWork. I’m not sure if this answers your second question too, so maybe you need to elaborate.

  3. Assuming your running a Spring Boot application, for the query side of your application you can create a Component/Service bean which has @EventHandler annotated functions for the events it is interested in.
    That’s it! The Axon Spring Boot auto configuration will see the service/component and wrap it into an EventProcessor which will be called when new events are published.
    Hoping this helps you out!

Cheers, Steven