Hi,
I’m having a bit of trouble understanding the behaviour of AggregateIdentifier when used with MongoDB and SpringBoot.
I seem to be able to easily replay ‘Create’ commands using the same AggregateIdentifier (a UUID or even just “1234”).
I’ve exposed a rest endpoint which takes ‘create’ commands and turns then into Java commands with @TargetAggregateIdentifier annotations that can be processed by Axon. However, if I repeat the request with the same aggregate ID many times, rather than getting some kind of exception like MongoException.DuplicateKey Axon just seems to happily continue creating duplicate Aggregates.
Here’s some output resulting from 2 calls from Mongo:
{ “_id” : ObjectId(“56a1454a3f96ab79b9a78e1f”), “aggregateIdentifier” : “1234”, “sequenceNumber” : NumberLong(0), “serializedPayload” : “<com.soagrowers.product.events.ProductAddedEvent>1234Awesome Drill</com.soagrowers.product.events.ProductAddedEvent>”, “timeStamp” : “2016-01-21T20:53:30.921Z”, “type” : “ProductAggregate”, “payloadType” : “com.soagrowers.product.events.ProductAddedEvent”, “payloadRevision” : null, “serializedMetaData” : “”, “eventIdentifier” : “28c189d5-def4-4400-8ae0-aa995841f1ff” }
{ “_id” : ObjectId(“56a1454b3f96ab79b9a78e20”), “aggregateIdentifier” : “1234”, “sequenceNumber” : NumberLong(0), “serializedPayload” : “<com.soagrowers.product.events.ProductAddedEvent>1234Awesome Drill</com.soagrowers.product.events.ProductAddedEvent>”, “timeStamp” : “2016-01-21T20:53:31.845Z”, “type” : “ProductAggregate”, “payloadType” : “com.soagrowers.product.events.ProductAddedEvent”, “payloadRevision” : null, “serializedMetaData” : “”, “eventIdentifier” : “793cc97b-1803-44fb-a7ff-5217a8c344aa” }
As you can see, the AggregateID’s are identical. However, the ObjectId and eventIdentifiers are both different. I’m not sure how these get created, but I realise they may have an impact on uniqueness.
Where am I going wrong? Can anyone help?
I’m using Axon 2.4.1 with the ‘mongo latest’ docker image on ubuntu 14.04.
My full code is here: https://github.com/benwilcock/microservice-sampler
Cheers
Ben