0

I have this code:

@Saga
@Slf4j
public class ActionsSaga2 {

    @Autowired
    transient CommandGateway commandGateway;

    @Autowired
    transient ActionService actionService;

    String id;
    ApplicationState state;

    @StartSaga
    @SagaEventHandler(associationProperty = "applicationId")
    public void on(ApplicationCreatedEvent event) {
        id = event.getApplicationId();
        state = event.getState();
        commandGateway.send(ScheduleActionCommand.builder()
                                    .applicationId(event.getApplicationId())
                                    .actionId(id)
                                    .targetState(event.getState())
                                    .build());

    }

    @EndSaga
    @SagaEventHandler(associationProperty = "applicationId")
    public void on(ActionDoneEvent event) {
        assert id != null;
    }

}

First @SagaEventHandler on(ApplicationCreatedEvent event) sets the private fields id and state.
But in the second @SagaEventHandler on(ActionDoneEvent event) both properties are null.

I'm pretty sure that the calls are routed to the same saga (the only record in saga_entry that is deleted after the second method call)

Could you help me where is the problem?

I have no special configuration for saga, using AxonServer and Spring boot

Tomáš Mika
  • 210
  • 1
  • 13

1 Answers1

0

I found the solution, the problem was in the association property.

correct event handler is

@EndSaga
    @SagaEventHandler(associationProperty = "applicationId", keyName = "id")
    public void on(ActionDoneEvent event) {
        assert id != null;
    }
Tomáš Mika
  • 210
  • 1
  • 13