Skip to content

Latest commit

 

History

History
41 lines (36 loc) · 1.08 KB

README.md

File metadata and controls

41 lines (36 loc) · 1.08 KB

biz-boot-starter-sequence

项目介绍

基于zookeepersnowflake算法的分布式id生成器

使用方法

  1. 添加pom依赖
    <dependency>
        <groupId>cn.waynechu</groupId>
        <artifactId>biz-boot-starter-sequence</artifactId>
    </dependency>
    
  2. 添加配置
    sequence.enable=true
    sequence.registryFile=./tmp/sequence
    sequence.zookeeper.serverLists=localhost:2181,localhost:2182,localhost:2183
    sequence.zookeeper.namespace=sequence
    
  3. 注入IdGenerator对象
    @Autowire
    private IdGenerator idGenerator;
    
  4. 生成分布式id
    long id = idGenerator.nextId();
    long[] ids = idGenerator.nextIds(1000);
    String idStr = idGenerator.nextStringId();
    String[] idsStr = idGenerator.nextStringIds(1000);
    ...
    

其他解决方案

  1. 基于UUID
  2. Redis分布式自增ID
  3. 百度UID-Generator,支持雪花ID模式。https://github.com/baidu/uid-generator
  4. 美团Leaf分布式ID生成器,支持号段模式和雪花ID模式。https://github.com/Meituan-Dianping/Leaf