克隆代码
git clone https://github.com/didi/tinyid.git
创建表
cd tinyid/tinyid-server/ && create table with db.sql (mysql)
配置数据库
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
启动tinyid-server
cd tinyid-server/
mvn clean package
java -jar target/tinyid-server-xxx.jar
在项目中添加tinyid-client依赖
<dependency>
<groupId>com.xiaoju.uemc.tinyid</groupId>
<artifactId>tinyid-client</artifactId>
<version>${tinyid.version}</version>
</dependency>
创建 tinyid_client.properties 内容如下
tinyid.server=localhost:9999
tinyid.token=0f673adf80504e2eaa552f5d791b644c
Java Code
Long id = TinyId.nextId("test");
List<Long> ids = TinyId.nextId("test", 10);
12月 12, 2022 10:47:54 上午 com.xiaoju.uemc.tinyid.client.utils.PropertiesLoader loadProperties
信息: Loading properties file from path:tinyid_client.properties
12月 12, 2022 10:47:54 上午 com.xiaoju.uemc.tinyid.client.factory.impl.IdGeneratorFactoryClient init
信息: init tinyId client success url info:[http://localhost:9999/tinyid/id/nextSegmentIdSimple?token=0f673adf80504e2eaa552f5d791b644c&bizType=]
12月 12, 2022 10:47:54 上午 com.xiaoju.uemc.tinyid.client.service.impl.HttpSegmentIdServiceImpl getNextSegmentId
信息: tinyId client getNextSegmentId end, response:700001,720001,800001,1,0