Aggregate's client generated identifiers

35 views
Skip to first unread message

Plamen Stojanov

unread,
Jan 20, 2017, 7:04:55 AM1/20/17
to Axon Framework Users
Hi Allard,

I'm using client generated identifiers for Aggregates in a microservice environment. It is a common case one service to initiate aggregate create command to another service.
In my architecture I'm using REST API for sending commands between microservices. (I'm having my reasons to prefer this approach vs distributed command bus).

Eventually it can happen, that one microservice can repeat CreateXyzCommand to the Aggregate owner's microservice. If this happens I need to be able to handle it and send an appropriate HTTP status code to the caller, so that it is aware that requested Aggregate was already created.

In order to do this I need some specific exception (for example: DuplicateIdentifierException) to be thrown, when I try to create aggregate with identifier, that already exists. Now I get some general purpose EventStoreException, that does not tell what is the reason for the failure. I don't want to handle this behavior in my command handlers or services (unfortunately what I'm doing now)

What do you think?

Cheers,
Plamen

Allard Buijze

unread,
Jan 22, 2017, 3:22:22 PM1/22/17
to Axon Framework Users
Hi Plamen,

it's actually already possible to identify this case. If you configure your EventStorageEngine with a PersistenceExceptionResolver (or a DataSource, in which case one is automatically configured based on the type of database backing your applicaiton). The PersistenceExceptionResolver checks if the exception thrown from the EntityManager is a DuplicateKeyException. In that case, the JpaEventStorageEngine throws a ConcurrencyException instead of the generic EventStorageException.

Cheers,

Allard

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages