天天看點

Spring Statemachine Using Distributed States

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叢集;