spring-projects / spring-statemachine

Spring Statemachine is a framework for application developers to use state machine concepts with Spring.
1.51k stars 598 forks source link

How to add new ReactiveActions to StateMachineConfiguration? #1134

Open davefarrelly opened 5 months ago

davefarrelly commented 5 months ago

Hi, I am looking to upgrade to v4.0.0 and switch to the new ReactiveActions , however I am not entirely sure how to migrate my project.

Currently I have a StateMachineConfiguration and I add the Actions to the states using the StateMachineStateConfigurer

@Override
public void configure(StateMachineStateConfigurer<CommitState, CommitEvent> states) throws Exception {
    states.withStates()
            .initial(CommitState.BEFORE_COMMIT)
            .state(CommitState.COMMIT_BLOCKS, commitStateService.commitBlocks())
            .end(CommitState.COMPLETE);
}

Where the Action is defined as:

public Action<CommitState, CommitEvent> commitBlocks() {
    return context -> {
      UUID uploadSessionId = getStateMachineId(context.getStateMachine());

      digestStrategyContext.commitBlockLists(uploadSessionId)
          .doOnSuccess(result -> sendEvent(context, CommitEvent.COMMIT_SUCCESS))
          .subscribe();
    };
}

It technically works, but of course isn't ideal as I am subscribing here inside the action and breaking my reactive chain. But if I create a new ReactiveAction that returns a Mono, how do I actually add it to the state like .state(CommitState.COMMIT_BLOCKS, commitStateService.commitBlocks()) ?