Search code examples
axon

Using Axon for CQRS and event sourcing. Aggregate not found in event store


I am new to Axon and have written a sample code wherein we have an inventory service which is used for adding new inventory, updating inventory and we want to send events to Product Service for any update. Product service should act as a read replica to Inventory Service.

Inventory Service code:

So I created Inventory Aggregate which various command handlers. enter image description here

Inventory Controller responsible for sending commands

enter image description here

In product Service, I added event handlers

enter image description here

Problem i am facing currently is, when i add a new inventory, it gets reflected in product service db but when i try to do update, it gives me an exception: Command 'com.example.demo.command.UpdateInventoryCommand' resulted in org.axonframework.commandhandling.CommandExecutionException(The aggregate was not found in the event store) org.axonframework.axonserver.connector.command.AxonServerRemoteCommandHandlingException: An exception was thrown by the remote message handling component: The aggregate was not found in the event store

When i try to make one more insert into inventory, Inventory Service throws Exception saying:

: "OUT_OF_RANGE: [AXONIQ-2000] Invalid sequence number 0 for aggregate 0, expected 1", An exception was thrown by the remote message handling component: OUT_OF_RANGE: [AXONIQ-2000] Invalid sequence number 0 for aggregate 0, expected 1 Caused by OUT_OF_RANGE: [AXONIQ-2000] Invalid sequence number 0 for aggregate 0, expected 1

Any help would be really appreciated. Complete code available at :

https://github.com/jahanvibansal/Axon-ProductService

https://github.com/jahanvibansal/Axon-InventoryOrderService


Solution

  • . I realized we need to specify axon.eventhandling.processors.name.mode=tracking property in spring boot application which got it working. I understand there are 2 modes tracking and publish subscribe. I would read more about it.