associationProperty in Saga with multiple events

Hi everyone,

A common case I have come along is a saga that sends multiple commands to different aggregate instances of the same aggregate and collects the events to end the workflow in a single step. To associate the saga to the multiple events I created a special field “traceId” in the events. But this is essentially the same as the “traceId” in the metadata of the events. Is there a way to use the metadata to correlate the events or is it necessary to create a duplicate property for this?

Another way I saw is to use SagaLifecycle.associateWith() to associate the Saga with each single aggregateId the saga sent a command for. Does this perform even for hundrets of such associations?

What is the better way to correlate such events? Is there another way to do this?


Hello Marc,

the associateWith() is intended exactly for this. Having hundreds of associations should be not problem at all (although it does sound like much).
It is also fine to use meta data to correlate events with Saga instances. You can specify a different strategy for looking up AssociationValues from Events. The default is to check for a property on the payload, but you can also use the Meta-Data:
@SagaEventHandler(associationProperty=“traceId”, associationResolver=MetaDataAssociationResolver.class)

Hope this helps.