distributed-tool 分布式常用工具组件 项目简介
项目介绍一个分布式常用工具组件。例如:分布式缓存、分布式序列号生成器、分布式锁、分布式订阅发布等等。软件架构目前项目分两个module,distributed-tool和distributed-tool-test。前者是核心源码。后者是测试代码。distributed-tool主要分如下组件:client 所有的核心组件依赖模块,主要提供了最简单的分布式set、get、del、incre等操作。(V1.0支持)cache 简单的分布式缓存模块。(V1.0支持)sequence 分布式序列号生成组件。(V1.0支持)版本更新V1.0 支持分布式缓存、分布式序列号生成组件Maven引用<dependency>
<groupId>com.xuanner</groupId>
<artifactId>distributed-tool</artifactId>
<version>1.0</version>
</dependency>使用说明(1)核心Client使用(一般不建议直接使用,但是后面的所有分布式组件都基于他来开发的,目前使用了Redis来做实现方案)构建DtClientprotected DtClient buildClient() {
RedisClient redisClinet = new RedisClient();
redisClinet.setHost("localhost");
redisClinet.setPort(1234);
redisClinet.setAuth("1234");
redisClinet.init();
return redisClinet;
}代码使用protected DtClient buildClient() {
DtClient client = buildClient();
client.set("key", "value", 10);
client.get("key");
client.del("key");
client.exists("key");
}(2)分布式缓存工具使用构建CacheClientprotected CacheClient buildCacheClient() {
DefaultCacheClient defaultCacheClient = new DefaultCacheClient();
defaultCacheClient.setClient(buildClient());
return defaultCacheClient;
}代码使用CacheClient cacheClient = buildCacheClient();
cacheClient.set("key", "value", 60);
cacheClient.get("key");
cacheClient.del("key");
cacheClient.setBulk(map, 60);
cacheClient.getBulk(list);
cacheClient.del(list);(3)分布式序列号使用构建Sequenceprotected Sequence buildSequence() {
DefaultSequence defaultSequence = new DefaultSequence();
defaultSequence.setClient(buildClient());
defaultSequence.setStep(1000);//步长,如果需要严格连续序号可以设置:1
defaultSequence.setStepStart(0);//序列号开始位置
return defaultSequence;
}代码使用Sequence sequence = buildSequence();
sequence.nextId();后续支持功能分布式订阅发布(通知功能)分布式锁联系方式姓名:徐安邮箱:[email protected]:349309307个人博客:xuanner.com
<groupId>com.xuanner</groupId>
<artifactId>distributed-tool</artifactId>
<version>1.0</version>
</dependency>使用说明(1)核心Client使用(一般不建议直接使用,但是后面的所有分布式组件都基于他来开发的,目前使用了Redis来做实现方案)构建DtClientprotected DtClient buildClient() {
RedisClient redisClinet = new RedisClient();
redisClinet.setHost("localhost");
redisClinet.setPort(1234);
redisClinet.setAuth("1234");
redisClinet.init();
return redisClinet;
}代码使用protected DtClient buildClient() {
DtClient client = buildClient();
client.set("key", "value", 10);
client.get("key");
client.del("key");
client.exists("key");
}(2)分布式缓存工具使用构建CacheClientprotected CacheClient buildCacheClient() {
DefaultCacheClient defaultCacheClient = new DefaultCacheClient();
defaultCacheClient.setClient(buildClient());
return defaultCacheClient;
}代码使用CacheClient cacheClient = buildCacheClient();
cacheClient.set("key", "value", 60);
cacheClient.get("key");
cacheClient.del("key");
cacheClient.setBulk(map, 60);
cacheClient.getBulk(list);
cacheClient.del(list);(3)分布式序列号使用构建Sequenceprotected Sequence buildSequence() {
DefaultSequence defaultSequence = new DefaultSequence();
defaultSequence.setClient(buildClient());
defaultSequence.setStep(1000);//步长,如果需要严格连续序号可以设置:1
defaultSequence.setStepStart(0);//序列号开始位置
return defaultSequence;
}代码使用Sequence sequence = buildSequence();
sequence.nextId();后续支持功能分布式订阅发布(通知功能)分布式锁联系方式姓名:徐安邮箱:[email protected]:349309307个人博客:xuanner.com