Hello,
I am currently working on a project where I am using the following technologies:
- Axon Framework version 4.5.15
- Spring Boot 2.3.10.RELEASE
- Java 8
My application is running on 4 pods in a production environment. It utilizes PostgreSQL as an event store. I’m using the simple command bus to dispatch commands. In this project, I have defined an aggregate with commands and event sourcing handlers.
However, sometimes, I am encountering a ConcurrencyException when handling a command, specifically:
“Command resulted in org.axonframework.modelling.command.ConcurrencyException: An event for aggregate [<aggregate_id>] at sequence was already inserted.”
Here’s an example code snippet of my aggregate definition for reference:
@Aggregate
public class MyAggregate {
@AggregateIdentifier
private String aggregateId;
@CommandHandler
public void handle(SomeCommand command) {
AggregateLifecycle.apply(new SomeEvent());
}
@EventSourcingHandler
public void on(SomeEvent event) {
// Perform some logic
}
}
How can I guarantee that the specific aggregate will handle one command at a time, even if multiple commands are dispatched on different pods simultaneously to the same aggregate instance using the simple command bus? Do i need to use a different command bus implementation?
I appreciate any guidance or suggestions on implementing a solution for this scenario.
Thank you in advance!