Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/onevroad/snowflake-plus
An id producer of snowflake for spring boot
https://github.com/onevroad/snowflake-plus
java snowflake spring-boot zookeeper
Last synced: 24 days ago
JSON representation
An id producer of snowflake for spring boot
- Host: GitHub
- URL: https://github.com/onevroad/snowflake-plus
- Owner: onevroad
- License: apache-2.0
- Created: 2019-07-16T07:37:41.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-11-16T09:26:48.000Z (about 2 years ago)
- Last Synced: 2024-10-29T22:56:38.819Z (2 months ago)
- Topics: java, snowflake, spring-boot, zookeeper
- Language: Java
- Homepage:
- Size: 63.5 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# snowflake-plus [![License](http://img.shields.io/:license-apache-brightgreen.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
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
```xmlorg.onevroad
snowflake-plus-core
0.3.0```
- add zookeeper's dependency(if your work-type is zookeeper)
```xmlorg.apache.curator
curator-recipes
4.2.0```
- add config
```yaml
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
```java
@RestController
public class SnowflakeIdController {@Autowired
private SnowflakeService snowflakeService;@GetMapping("/snowflake/id/get")
public long getId() {
return snowflakeService.getId();
}
}
```## Feature
- support other work-type