org.onevroad:snowflake-plus-core

a Java distributed id generator, snowflake with zookeeper

License

License

GroupId

GroupId

org.onevroad
ArtifactId

ArtifactId

snowflake-plus-core
Last Version

Last Version

0.3.0
Release Date

Release Date

Type

Type

jar
Description

Description

a Java distributed id generator, snowflake with zookeeper

Download snowflake-plus-core

How to add to project

<!-- https://jarcasting.com/artifacts/org.onevroad/snowflake-plus-core/ -->
<dependency>
    <groupId>org.onevroad</groupId>
    <artifactId>snowflake-plus-core</artifactId>
    <version>0.3.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.onevroad/snowflake-plus-core/
implementation 'org.onevroad:snowflake-plus-core:0.3.0'
// https://jarcasting.com/artifacts/org.onevroad/snowflake-plus-core/
implementation ("org.onevroad:snowflake-plus-core:0.3.0")
'org.onevroad:snowflake-plus-core:jar:0.3.0'
<dependency org="org.onevroad" name="snowflake-plus-core" rev="0.3.0">
  <artifact name="snowflake-plus-core" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.onevroad', module='snowflake-plus-core', version='0.3.0')
)
libraryDependencies += "org.onevroad" % "snowflake-plus-core" % "0.3.0"
[org.onevroad/snowflake-plus-core "0.3.0"]

Dependencies

compile (6)

Group / Artifact Type Version
org.projectlombok : lombok jar
org.slf4j : slf4j-api jar
commons-io : commons-io jar 2.4
com.google.guava : guava jar 28.0-jre
org.springframework.boot : spring-boot-autoconfigure jar
org.springframework.boot : spring-boot-configuration-processor Optional jar

provided (2)

Group / Artifact Type Version
org.apache.curator : curator-recipes jar 4.2.0
com.fasterxml.jackson.core : jackson-databind jar 2.9.9.2

Project Modules

There are no modules declared in this project.

snowflake-plus License

This is an id generator which use the snowflake algorithm. It's developed by spring-boot. This component works without configuring work-id. The idea of this component came from Meituan tech who designed the snowflake id with zookeeper.

Work Type

There are three types for the component.

  • local: The work-id will be got from your local application's properties file.
  • zookeeper: The work-id will be registered to your zookeeper server.
  • ip: The work-id will be got by the last part of your local server's IP. For example: If your IP is 192.168.1.200, the work-id is 200.

Quick Start

  • add maven dependency
<dependency>
    <groupId>org.onevroad</groupId>
    <artifactId>snowflake-plus-core</artifactId>
    <version>0.3.0</version>
</dependency>
  • add zookeeper's dependency(if your work-type is zookeeper)
<dependency>
    <groupId>org.apache.curator</groupId>
    <artifactId>curator-recipes</artifactId>
    <version>4.2.0</version>
</dependency>
  • add config
snowflake:
  plus:
    #local,zookeeper,ip. Default is local.
    work-type: zookeeper
    #initial start time, default: 2019-08-01 00:00:00 (UTC)
    start-time: 1564617600000
    #the number of bit for worker id, default: 8bit
    worker-id-bits: 8
    #the number of bit for sequence, default: 12bit
    sequence-bits: 12
    #If your work-type is local, you need configure the work-id
    worker-id: 1
    #If your work-type is zookeeper, you need configure the following parameters
    #application's registered name
    name: snowflake-plus-sample
    #application's registered port
    port: 8001
    #the zookeeper address
    zk-address: localhost:2181
  • get ID
@RestController
public class SnowflakeIdController {

    @Autowired
    private SnowflakeService snowflakeService;

    @GetMapping("/snowflake/id/get")
    public long getId() {
        return snowflakeService.getId();
    }
}

Feature

  • support other work-type

Versions

Version
0.3.0
0.1.1
0.1.0