Event sourced aggregate with multiple CreatedEvents in 3.0.3

I have simple app with following create-related methods in the aggregate

public Counter(CounterCreateCommand command, MetaData metaData) {
AggregateLifecycle.apply(new CounterCreatedEvent(command.getId()), metaData);

public void on(CounterCreatedEvent e) {
this.id = e.getId();
this.counter = 0;

It looks like I am able to issue the CounterCreateCommand multiple times, resulting into the CounterCreatedEvent being written each time.

I thought the framework will prevent double-creation of aggregate. Or am I missing something obvious here?

Hi Tomáš,

What is the id set to in your CounterCreateCommand?
Can you publish two CounterCreateCommands with identical id’s, or is the ‘issuing of multiple commands’ you refer to creating a CounterCreateCommand with unique ids?
As far as I know, that should result in an exception when your CounterCreatedEvent is trying to be stored, because you’d try storing a second CounterCreatedEvent with an identical aggregate identifier and sequence number.

Hope this helps!



Well that’s exactly what I expected as well - some kind of error flow. And yes, I am using the same id, the configuration is like this:

public static void main(String[] args) throws Exception {
Configurer configurer = DefaultConfigurer
.configureEmbeddedEventStore(c -> new InMemoryEventStorageEngine())

Configuration configuration = configurer.buildConfiguration();

String id = “my-static-id”;
configuration.commandGateway().sendAndWait(new CounterCreateCommand(id));
configuration.commandGateway().sendAndWait(new CounterCreateCommand(id));


The console output:

DEBUG [main] (Counter.java:28) - +++ CounterCreateCommand received for my-static-id created 391359742 DEBUG [main] (Counter.java:36) - + counter my-static-id consuming create : 391359742 DEBUG [main] (Counter.java:28) - +++ CounterCreateCommand received for my-static-id created 485041780 DEBUG [main] (Counter.java:36) - + counter my-static-id consuming create : 485041780 org.axonframework.eventsourcing.GenericTrackedDomainEventMessage@20322d26 org.axonframework.eventsourcing.GenericTrackedDomainEventMessage@192b07fd

Hi Tomas,

it seems you’re using the InMemoryEventStorageEngine. That one (for some reason) doesn’t check for uniqueness. It just adds all published events to a list.
You’re better off using the JpaEventStorageEngine with an InMemory database if you want to be “production compatible”.



Thanks Allard. I am actually using the MongoEventStorageEngine

new MongoEventStorageEngine(new DefaultMongoTemplate(new MongoClient(""), "axonframework", "domainevents", "snapshotevents"))

but with the same result. The Mongo is v3.4 just fresh install. Anyway atm I will move away from mongo in favour of couchbase. I can see that this is solved in AbstractEventStorageEngine by the datastore throwing an exception and being handled properly.


Hi Tomas,

are the indexes in place? There should be a unique index on the aggregateIdentifier and sequenceNumber properties. If there isn’t, you can create it by calling “ensureIndexes” on your MongoEventStorageEngine instance.



No, they weren’t created. When adding the index manually all worked as expected.