java idgenerator_ID Generator id生成器 分布式id生成系统

Tinyid是一个ID生成服务,提供REST API和Java客户端,单实例支持超过1000万QPS。它包括创建数据库表、配置数据库、启动服务、使用REST API和Java客户端获取ID的步骤。Tinyid可用于生成连续或间隔的ID,适用于分布式系统。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Tinyid

687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d417061636865322e302d627269676874677265656e2e7376673f7374796c653d666c617468747470733a2f2f696d672e736869656c64732e696f2f62616467652f5052732d77656c636f6d652d627269676874677265656e2e737667

Tinyid is a ID Generator Service. It provides a REST API and a java client for getting ids. Over 10 million QPS per single instance when using the java client. Support jdk version 1.7+

Getting started

Clone code

Create table

cd tinyid/tinyid-server/ && create table with db.sql (mysql)

Config db

cd tinyid-server/src/main/resources/offline

vi application.properties

datasource.tinyid.names=primary

datasource.tinyid.primary.driver-class-name=com.mysql.jdbc.Driver

datasource.tinyid.primary.url=jdbc:mysql://ip:port/databaseName?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8

datasource.tinyid.primary.username=root

datasource.tinyid.primary.password=123456

Start tinyid-server

cd tinyid-server/

sh build.sh offline

java -jar output/tinyid-server-xxx.jar

REST API

nextId:

curl 'http://localhost:9999/tinyid/id/nextId?bizType=test&token=0f673adf80504e2eaa552f5d791b644c'

response:{"data":[2],"code":200,"message":""}

nextId Simple:

curl 'http://localhost:9999/tinyid/id/nextIdSimple?bizType=test&token=0f673adf80504e2eaa552f5d791b644c'

response: 3

with batchSize:

curl 'http://localhost:9999/tinyid/id/nextIdSimple?bizType=test&token=0f673adf80504e2eaa552f5d791b644c&batchSize=10'

response: 4,5,6,7,8,9,10,11,12,13

Get nextId like 1,3,5,7,9...

bizType=test_odd : delta is 2 and remainder is 1

curl 'http://localhost:9999/tinyid/id/nextIdSimple?bizType=test_odd&batchSize=10&token=0f673adf80504e2eaa552f5d791b644c'

response: 3,5,7,9,11,13,15,17,19,21

Java client (Recommended)

Maven dependency

com.xiaoju.uemc.tinyid

tinyid-client

${tinyid.version}

Create tinyid_client.properties in your classpath

tinyid_client.properties:

tinyid.server=localhost:9999

tinyid.token=0f673adf80504e2eaa552f5d791b644c

#(tinyid.server=localhost:9999/gateway,ip2:port2/prefix,...)

Java Code

Long id = TinyId.nextId("test");

List ids = TinyId.nextId("test", 10);

Communication

Contributing

Welcome to contribute by creating issues or sending pull requests. See Contributing Guide for guidelines.

License

Tinyid is licensed under the Apache License 2.0. See the LICENSE file.

Note

This is not an official Didi product (experimental or otherwise), it is just code that happens to be owned by Didi.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值