Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distributed lock #813

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Distributed lock #813

wants to merge 5 commits into from

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