Simba旨在提供易用、灵活的分布式锁服务,支持多种存储后端实现:关系型数据库、Redis、Zookeeper。
安装GradleKotliDSLvalsimbaVersio="0.3.2";implemetatio("me.ahoo.simba:simba-sprig-boot-starter:${simbaVersio}") Mave<?xmlversio="1.0"ecodig="UTF-8"?><projectxmls="https://mave.apache.org/POM/4.0.0"xmls:xsi="https://www.w3.org/2001/XMLSchema-istace"xsi:schemaLocatio="https://mave.apache.org/POM/4.0.0https://mave.apache.org/xsd/mave-4.0.0.xsd"><modelVersio>4.0.0</modelVersio><artifactId>demo</artifactId><properties><simba.versio>0.3.2</simba.versio></properties><depedecies><depedecy><groupId>me.ahoo.simba</groupId><artifactId>simba-sprig-boot-starter</artifactId><versio>${simba.versio}</versio></depedecy></depedecies></project> applicatio.yamlsimba:jdbc:eabled:true#redis:#eabled:truesprig:datasource:url:jdbc:mysql://localhost:3306/simba_dbuserame:rootpassword:root Optioal-1:JdbcMutexCotedServiceKotliDSLvalsimbaVersio="0.3.2";implemetatio("me.ahoo.simba:simba-jdbc:${simbaVersio}") createtablesimba_mutex(mutexvarchar(66)otullprimarykeycommet'mutexame',acquired_atbigitusigedotull,ttl_atbigitusigedotull,trasitio_atbigitusigedotull,ower_idchar(32)otull,versioitusigedotull); Optioal-2:RedisMutexCotedServiceKotliDSLvalsimbaVersio="0.3.2";implemetatio("me.ahoo.simba:simba-redis:${simbaVersio}")Optioal-3:ZookeeperMutexCotedServiceKotliDSLvalsimbaVersio="0.3.2";implemetatio("me.ahoo.simba:simba-zookeeper:${simbaVersio}") ExamplesSimba-Examples使用入门MutexCotederMutexCotedServicecotedService=cotedServiceFactory.createMutexCotedService(ewAbstractMutexCoteder(mutex){@OverridepublicvoidoAcquired(MutexStatemutexState){log.ifo("oAcquired");}@OverridepublicvoidoReleased(MutexStatemutexState){log.ifo("oReleased");}});cotedService.start(); SimbaLockertry(Lockerlocker=ewSimbaLocker("mutex-locker",this.mutexCotedServiceFactory)){locker.acquire(Duratio.ofSecods(1));/***doSomethig*/}catch(Exceptioe){log.error(e.getMessage(),e);} SchedulerpublicclassExampleSchedulerextedsAbstractSchedulerimplemetsSmartLifecycle{publicExampleScheduler(MutexCotedServiceFactorycotedServiceFactory){super("example-scheduler",ScheduleCofig.ofDelay(Duratio.ofSecods(0),Duratio.ofSecods(10)),cotedServiceFactory);}@OverrideprotectedStriggetWorker(){retur"ExampleScheduler";}@Overrideprotectedvoidwork(){if(log.isIfoEabled()){log.ifo("dosomework!");}}}UseCasesGover-EvetBusCoSky











评论