All Projects → imadcn → Idworker

imadcn / Idworker

Licence: apache-2.0
idworker 是一个基于zookeeper和snowflake算法的分布式ID生成工具,通过zookeeper自动注册机器(最多1024台),无需手动指定workerId和datacenterId

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Idworker

Herddb
A JVM-embeddable Distributed Database
Stars: ✭ 192 (+12.28%)
Mutual labels:  zookeeper, distributed
Xxl Conf
A lightweight distributed configuration management platform. (分布式配置管理平台XXL-CONF)
Stars: ✭ 619 (+261.99%)
Mutual labels:  zookeeper, distributed
toy-rpc
Java基于Netty,Protostuff和Zookeeper实现分布式RPC框架
Stars: ✭ 55 (-67.84%)
Mutual labels:  zookeeper, distributed
Cronner
Cronner 是一个分布式定时任务框架,支持作业依赖、分片、失效转移、集中配置和监控。
Stars: ✭ 51 (-70.18%)
Mutual labels:  zookeeper, distributed
piccolo
Netty4长连接网关
Stars: ✭ 19 (-88.89%)
Mutual labels:  snowflake, zookeeper
Repository
个人学习知识库涉及到数据仓库建模、实时计算、大数据、Java、算法等。
Stars: ✭ 92 (-46.2%)
Mutual labels:  algorithm, zookeeper
Bigdata docker
Big Data Ecosystem Docker
Stars: ✭ 161 (-5.85%)
Mutual labels:  zookeeper
Terraform Provider Snowflake
Terraform provider for managing Snowflake accounts
Stars: ✭ 165 (-3.51%)
Mutual labels:  snowflake
Paper checking system
基于C#和C++开发的文本查重/论文查重系统,一亿字次级论文库秒级查重。关联:查重算法、数据去重、文档查重、文本去重、标书查重、辅助防串标
Stars: ✭ 160 (-6.43%)
Mutual labels:  algorithm
Python data structures and algorithms
Python 中文数据结构和算法教程
Stars: ✭ 2,194 (+1183.04%)
Mutual labels:  algorithm
Snowflakes
❄️ Snowflakes in JavaScript
Stars: ✭ 170 (-0.58%)
Mutual labels:  snowflake
Albert
这个是我个人网站的项目,欢迎贡献代码,力求能够应用到实际工作中java相关的大多数技术栈。有兴趣请Star一下,非常感谢。qq交流群:587577705 这个项目将不断地更新!生产环境:
Stars: ✭ 168 (-1.75%)
Mutual labels:  zookeeper
Fe Interview
宇宙最强的前端面试指南 (https://lucifer.ren/fe-interview)
Stars: ✭ 2,284 (+1235.67%)
Mutual labels:  algorithm
Internet Recruiting Algorithm Problems
《程序员代码面试指南》、公司招聘笔试题、《剑指Offer》、算法、数据结构
Stars: ✭ 163 (-4.68%)
Mutual labels:  algorithm
Boostaroota
A fast xgboost feature selection algorithm
Stars: ✭ 165 (-3.51%)
Mutual labels:  algorithm
Pifpaf
Python fixtures and daemon managing tools for functional testing
Stars: ✭ 161 (-5.85%)
Mutual labels:  zookeeper
Ahocorasickphp
Aho-Corasick multi-keyword string searching library in PHP.
Stars: ✭ 169 (-1.17%)
Mutual labels:  algorithm
Diztl
Share, discover & download files in your network 💥
Stars: ✭ 162 (-5.26%)
Mutual labels:  distributed
Textdistance
Compute distance between sequences. 30+ algorithms, pure python implementation, common interface, optional external libs usage.
Stars: ✭ 2,575 (+1405.85%)
Mutual labels:  algorithm
Leetcode Js
用 JS 刷 LeetCode
Stars: ✭ 165 (-3.51%)
Mutual labels:  algorithm

idworker - 基于zookeeper,snowflake的分布式统一ID生成工具

Build Status Coverage Status Maven Central License

是什么

idworker 是一个基于zookeeper和snowflake算法的分布式统一ID生成工具,通过zookeeper自动注册机器(最多1024台),无需手动指定workerId和dataCenterId

怎么用

Maven

<dependency>
  <groupId>com.imadcn.framework</groupId>
  <artifactId>idworker</artifactId>
  <version>${latest.version}</version>
</dependency>

XML

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:idworker="http://code.imadcn.com/schema/idworker"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://code.imadcn.com/schema/idworker
        http://code.imadcn.com/schema/idworker/idworker.xsd">
        
    <idworker:registry id="zkRegistryCenter" server-lists="host1:port1,host2:port2"/>
    <idworker:generator id="snowflakeGenerator" registry-center-ref="zkRegistryCenter" />
</beans>

API

@Autowired
public IdGenerator generator;

public void id() {
    long id = generator.nextId(); // Long型ID(64进制UUID不支持),随着时间推移,ID长度为7-19位
    long[] ids = generator.nextId(100_000); // 批量Long型ID(64进制UUID不支持),最多10w个
	
    String strId = generator.nextStringId(); // 字符串格式ID
    String fixedId = generator.nextFixedStringId(); // 固定19位长度字符串Id
}

配置参考

<idworker:registry /> 注册中心配置,如zookeeper(64进制UUID策略可不配置注册中心)

属性 类型 必填 缺省值 兼容版本 描述
id String 1.0.0+ Spring容器中的ID
server-lists String 1.0.0+ 连接Zookeeper服务器的列表
包括IP地址和端口号
多个地址用逗号分隔
如: host1:2181,host2:2181
namespace String idworker 1.0.0+ Zookeeper的命名空间
base-sleep-time-milliseconds int 1000 1.0.0+ 等待重试的间隔时间的初始值
单位:毫秒
max-sleep-time-milliseconds int 3000 1.0.0+ 等待重试的间隔时间的最大值
单位:毫秒
max-retries int 3 1.0.0+ 最大重试次数
session-timeout-milliseconds int 60000 1.0.0+ 会话超时时间
单位:毫秒
connection-timeout-milliseconds int 15000 1.0.0+ 连接超时时间
单位:毫秒
digest String 1.0.0+ 连接Zookeeper的权限令牌
缺省为不需要权限验证

<idworker:generator /> ID生成策略配置

属性 类型 必填 缺省值 兼容版本 描述
id String 1.0.0+ Spring容器中的ID
strategy String snowflake 1.2.0+ ID生成[snowflake, compress_uuid],当策略为64进制uuid时,registry-center-ref可不用配置
registry-center-ref String 1.0.0+ 注册中心SpringBeanRef,当生成策略为snowflake时,必填
group String default 1.0.0+ 分组名,可以为不同业务分配分组,独立注册
registry-file String ./tmp/idworker/GROUPNAME.cache 1.3.0+ 注册信息缓存文件地址,默认在程序所在目录 ./tmp/idworker/GROUPNAME.cache
durable String false 1.4.0+ ID注册信息是否持久化存储(持久化存储会依赖于本地缓存文件,容器环境建议使用非持久化)

<generator:snowflake /> 生成策略 : snowflake模式

属性 类型 必填 缺省值 兼容版本 描述
id String 1.2.0+ Spring容器中的ID
registry-center-ref String 1.2.0+ 注册中心SpringBeanRef
group String default 1.2.0+ 分组名,可以为不同业务分配分组,独立注册
registry-file String ./tmp/idworker/GROUPNAME.cache 1.3.0+ 注册信息缓存文件地址,默认在程序所在目录 ./tmp/idworker/GROUPNAME.cache
durable String false 1.4.0+ ID注册信息是否持久化存储(持久化存储会依赖于本地缓存文件,容器环境建议使用非持久化)

<generator:compress-uuid /> 生成策略 : 64进制UUID模式

属性 类型 必填 缺省值 兼容版本 描述
id String 1.2.0+ Spring容器中的ID
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].