Spring Statemachine 提供了分布是状态及,目前最新版本为2.1.2.RELEASE,此功能还是preview feature,但是经过查看源码和简单测试,上生产环境问题不大;
Spring Statemachine Distributed States基于Zookeeper提供的CP能力,将状态机的配置持久花到zookeeper集群,一个Spring Statemachine集群中的Statemachine都watch同一个zookeeper path;
zookeeper的watch,notify一次之后就校徽,Spring Statemachine使用了一个巧妙的方法,为一个状态及创建多个path副本,循环使用,这样的一批目录对于Spring Statemachine来说,代表一个状态及。此部分的具体逻辑体现在org.springframework.statemachine.zookeeper.ZookeeperStateMachinePersist<S, E>中。
大家可以运行官方仓库中的web是例,及相关模块的源码,以加深理解。
Distributed States Semantics
Spring Statemachine的分布是指在不同的进程中,连接到同一个zookeeper path, 各自创建Statemachine 实例,这些Statemachine 实例会组成一个StateMachineEnsemble,也就是一个分布是的Statemachine集群;