Docs:
How does the “@SagaEventHandler(associationProperty=“sellOrderId”, keyName=“orderId”)” works?
I do not understand the doc.
The example below will not work since we erase the association key.
How to solve this issue?
One way is to change EventC and EventD for field “token” to have unique field name but that is not always possible.
Also I would rather use different token for each command so the corresponding event published have different token as well.
Example:
Have event:
EventA with field “myCustomId” (field is an object with custom toString()) => is published by Aggregate0
EventB with field “myCustomId” (field is an object with custom toString()) => is published by Aggregate0
EventC with string field “token” => is published by Aggregate1
EventD with string field “token” => is published by Aggregate2
`
@StartSaga
@SagaEventHandler(associationProperty = “myCustomId”)
public void handle(EventA event) {
var token1 = “random uuid value 1”
var token2 = “random uuid value 2”
// below associateWith does not work but events use both a field “token”
SagaLifecycle.associateWith(“token”, token1);
SagaLifecycle.associateWith(“token”, token2);
// send cmd1 to Aggregate1 with token1
commandGateway.send(cmd1);
// send cmd2 to Aggregate2 with token2
commandGateway.send(cmd2);
}
@SagaEventHandler(associationProperty = “token”)
public void handle(EventC event) {
// some logic
}
@SagaEventHandler(associationProperty = “token”)
public void handle(EventD event) {
// some logic
}
@EndSaga
@SagaEventHandler(associationProperty = “myCustomId”)
public void handle(EventB event) {
}
`