Hi Folks,
I’m trying to understand the essence of the saga association.
If I got it right, the associationProperty is used for the routing of an Event to specific Saga instance. Having an events
class Foo {
private MyType myId;
}
class Bar {
private MyType myId;
}
and writing a Saga:
class MySaga {
@StartSaga
@SagaEventHandler(accotiationProperty = “myId”)
public void on(Foo e) {
// do something here
}
@SagaEventHandler(accotiationProperty = “myId”)
public void on(Bar e) {
// do something here
}
}
would start a new Saga instance on receipt of Foo and assign the value of “myId” from the event to a (internal Saga) property myId (I could have renamed it by using the keyName, but this is just a detail).
Now if I had a second event Bar, using the the same assotication property myId (same type, same value) and an event handler in the Saga, the SAME Saga Instance will be called on the arrival of the Bar event.
This is simple routing, straight forward, but I want to have written it down.
Now I was reading the Chapter https://docs.axonframework.org/part2/sagas.html#managing-associations of Saga documentation and didn’t get the point there. You are writing that the Saga gets associated with “instances of those concepts”.
Do you mean Aggregate?
The association is somehow fuzzy - the aggregate publishes some Event with some property (not neccessarily an Aggregate Identifier) - it creates a “logical” connection between the aggregate and the saga.
It get even more unclear to me, if you describe the SagaLifecycle methods.
What are they for?
What is the purpose / intent / reason for assotication the Saga with Aggregates before sending commands to them?
Should the association executed with SagaLifecycle MEthods points to TargetAggregateIdentifiers inside of the commands?
Another question is, why do I have to use a String or a Number (and not ANY (nice = Java Bean, Serializable) type, like in AggregateIdentifier)?
Somehow it is just not stated in the docs why should I want to do so. I perfectly understand your business example - it makes absolutely sence, but the technical code snippet leaves some white spots…
Thanks
Kind regards,
Simon