intermediateOrchestration Saga

What does associationProperty do on a @SagaEventHandler, and why is it necessary?

associationProperty tells Axon which field on an incoming event to match against, so the event gets routed to the correct in-flight saga instance rather than an unrelated one. It's necessary because a real system typically has many instances of the same saga running concurrently — hundreds of loan approvals in progress at once, for example — and Axon needs a reliable way to know which specific saga instance a given event, like a FundsDepositedEvent for a particular account, actually belongs to. By declaring associationProperty = \"accountId\", the saga tells Axon to route that event to whichever saga instance is currently associated with that exact account ID. Without it, or with it set incorrectly, events can get routed to the wrong saga instance, or fail to find a matching instance at all, silently breaking the coordination the saga is supposed to provide.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to Why should a composed endpoint call multiple downstream services concurrently instead of one after another?← Back to all Event-Driven Microservices questions