Skip to content

Conversation

jesty
Copy link

@jesty jesty commented Oct 14, 2019

I'm using Spring Statemachine in a microservice cluster, so I have to face with concurrent access to a state machine from various microservice instances.

I can't use Zookeeper, so I decide to use a distributed lock using Redis.

In the pull request I implemented it using two open-source projects: Redisson and ShedLock.

Using ShedLock you can relay also on other systems like a SQL database and MongoDB.

To use it you have to configure a Guard where you would like to have the lock:

               transitions
                    .withExternal()
                    .guard(new LockStateMachineGuard<>(lockService, 120))
                    .source("S1").target("S2")
                    .event("E1")

To remove the lock when the transition ends you have to configure a listener:

              config
                    .withConfiguration()
                    .listener(lockListener)
                    .autoStartup(true);

I tried to implements it using a StateMachineInterceptor, but it doesn't work.

What do you think about the pull request? Can it be useful? If you would like to merge I can contribute also to documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant