distributed-tool,一个分布式常用工具组件 V1.0 发布

栏目: 软件资讯 · 发布时间: 7年前

内容简介:distributed-tool 项目介绍 一个分布式常用工具组件。例如:分布式缓存、分布式序列号生成器、分布式锁、分布式订阅发布等等。后续会持续加入一些常用的分布式(微服务)需要用到的策略和工具代码。 软件架构 目前...

distributed-tool

项目介绍

一个分布式常用 工具 组件。例如:分布式缓存、分布式序列号生成器、分布式锁、分布式订阅发布等等。后续会持续加入一些常用的分布式(微服务)需要用到的策略和工具代码。

软件架构

目前项目分两个module,distributed-tool和distributed-tool-test。前者是核心源码。后者是测试代码。
distributed-tool主要分如下组件:

  1. client 所有的核心组件依赖模块,主要提供了最简单的分布式set、get、del、incre等操作。(V1.0支持)

  2. cache 简单的分布式缓存模块。(V1.0支持)

  3. sequence 分布式序列号生成组件。(V1.0支持)

版本更新

  1. V1.0 支持分布式缓存、分布式序列号生成组件

Maven引用

<dependency>
    <groupId>com.xuanner</groupId>
    <artifactId>distributed-tool</artifactId>
    <version>1.0</version>
</dependency>

使用说明

(1)核心Client使用(一般不建议直接使用,但是后面的所有分布式组件都基于他来开发的,目前使用了 Redis 来做实现方案)

  • 构建DtClient

protected 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)分布式缓存工具使用

  • 构建CacheClient

protected 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)分布式序列号使用

  • 构建Sequence

protected Sequence buildSequence() {
    DefaultSequence defaultSequence = new DefaultSequence();
    defaultSequence.setClient(buildClient());
    defaultSequence.setStep(1000);//步长,如果需要严格连续序号可以设置:1
    defaultSequence.setStepStart(0);//序列号开始位置
    return defaultSequence;
}
  • 代码使用

Sequence sequence = buildSequence();
sequence.nextId();

后续支持功能

  1. 分布式订阅发布(通知功能)

  2. 分布式锁

联系方式

  1. 姓名:徐安

  2. 邮箱:javaandswing@163.com

  3. 个人博客:xuanner.com


【声明】文章转载自:开源中国社区 [http://www.oschina.net]


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Building Web Reputation Systems

Building Web Reputation Systems

Randy Farmer、Bryce Glass / Yahoo Press / 2010 / GBP 31.99

What do Amazon's product reviews, eBay's feedback score system, Slashdot's Karma System, and Xbox Live's Achievements have in common? They're all examples of successful reputation systems that enable ......一起来看看 《Building Web Reputation Systems》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具