I'm working in a reactive java project with spring state machine version 3.2.1. I need to reactively save and entity every time that the state changes.
Before, when I was using spring state machine 2.x without reactivity, I just had to extend StateMachineInterceptorAdapter and override preStateChange to get the entity id from the message header, then get the entity, update the entity status and save it. Something like this:
public class BookingMachineInterceptor extends StateMachineInterceptorAdapter<BookingState, BookingEvent> {
private final BookingRepository bookingRepository;
@Override
public void preStateChange(State<BookingState, BookingEvent> state, Message<BookingEvent> message,
Transition<BookingState, BookingEvent> transition, StateMachine<BookingState, BookingEvent> stateMachine,
StateMachine<BookingState, BookingEvent> rootStateMachine) {
Optional.ofNullable(message).ifPresent(msg -> {
Optional.ofNullable(UUID.class.cast(msg.getHeaders().get("booking_id")))
.ifPresent(bookingId -> {
Booking booking = bookingRepository.getOne(bookingId);
booking.setState(state I.getId());
bookingRepository.save(booking);
});
});
}
}
However, in ssm version 3.2.1 it seems that neither the interceptor nor the listeners interfaces support reactivity. Do you know how something similar could be achieved with the new ssm? Is it possible to listen to state changes and execute some reactive code that returns a Mono?