Axon 2 Events and the AggregateIdentifier

Library: 2.0-SNAPSHOT as of 2012-09-02 @ 14:00 PDT

In Axon 1.x the events would extend from DomainEvent and would have an accessor to the aggregate identifier. Since events no longer need to extend a framework base class what is the best practice for an event listener to get the aggregate identifier of an event: declared as a class attribute of the event; or, use the DomainEventMessage.getAggregateIdentifier()?

A SagaEventHandler and the associative key are based on an accessor method signature in the event. This ties into the question above… will the SagaEventHandler also look into the header of the EventMessage for data or only limit itself to the payload?


Hi Seamus,

in Axon 2, the best practice is to put your aggregate identifier as a custom field in your own event class. It’s best not to rely on the “getAggregateIdentifier” method on the DomainEventMessage at all.
In this case, the saga’s will be able to find the necessary association keys in the event as well.

Hope this helps.