Simba-Distributed-Mutex 分布式锁服务开源项目

我要开发同款
匿名用户2022年05月06日
63阅读
开发技术Java
所属分类服务器软件、分布式应用/网格
授权协议Apache

作品详情

Simba旨在提供易用、灵活的分布式锁服务,支持多种存储后端实现:关系型数据库、Redis、Zookeeper。

安装GradleKotlinDSL

valsimbaVersion="0.3.2";implementation("me.ahoo.simba:simba-spring-boot-starter:${simbaVersion}") Maven<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="https://maven.apache.org/POM/4.0.0"xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="https://maven.apache.org/POM/4.0.0https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><artifactId>demo</artifactId><properties><simba.version>0.3.2</simba.version></properties><dependencies><dependency><groupId>me.ahoo.simba</groupId><artifactId>simba-spring-boot-starter</artifactId><version>${simba.version}</version></dependency></dependencies></project> application.yamlsimba:jdbc:enabled:true#redis:#enabled:truespring:datasource:url:jdbc:mysql://localhost:3306/simba_dbusername:rootpassword:root Optional-1:JdbcMutexContendService

KotlinDSL

valsimbaVersion="0.3.2";implementation("me.ahoo.simba:simba-jdbc:${simbaVersion}") createtablesimba_mutex(mutexvarchar(66)notnullprimarykeycomment'mutexname',acquired_atbigintunsignednotnull,ttl_atbigintunsignednotnull,transition_atbigintunsignednotnull,owner_idchar(32)notnull,versionintunsignednotnull); Optional-2:RedisMutexContendServiceKotlinDSL

valsimbaVersion="0.3.2";implementation("me.ahoo.simba:simba-redis:${simbaVersion}")Optional-3:ZookeeperMutexContendServiceKotlinDSL

valsimbaVersion="0.3.2";implementation("me.ahoo.simba:simba-zookeeper:${simbaVersion}") ExamplesSimba-Examples

使用入门MutexContenderMutexContendServicecontendService=contendServiceFactory.createMutexContendService(newAbstractMutexContender(mutex){@OverridepublicvoidonAcquired(MutexStatemutexState){log.info("onAcquired");}@OverridepublicvoidonReleased(MutexStatemutexState){log.info("onReleased");}});contendService.start(); SimbaLockertry(Lockerlocker=newSimbaLocker("mutex-locker",this.mutexContendServiceFactory)){locker.acquire(Duration.ofSeconds(1));/***doSomething*/}catch(Exceptione){log.error(e.getMessage(),e);} SchedulerpublicclassExampleSchedulerextendsAbstractSchedulerimplementsSmartLifecycle{publicExampleScheduler(MutexContendServiceFactorycontendServiceFactory){super("example-scheduler",ScheduleConfig.ofDelay(Duration.ofSeconds(0),Duration.ofSeconds(10)),contendServiceFactory);}@OverrideprotectedStringgetWorker(){return"ExampleScheduler";}@Overrideprotectedvoidwork(){if(log.isInfoEnabled()){log.info("dosomework!");}}}UseCasesGovern-EventBusCoSky

 

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论