# distributed-id-example **Repository Path**: logtail/distributed-id-example ## Basic Information - **Project Name**: distributed-id-example - **Description**: 基于美团的leaf 实现分布式ID - **Primary Language**: Unknown - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2022-06-05 - **Last Updated**: 2022-06-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # distributed-id-example #### 介绍 基于美团的leaf 实现分布式ID #### 软件架构 底层基于美团leaf算法实现 #### YAML配置 ```yaml spring: application: name: distributed-id-server # 指定静态资源目录 mvc: static-path-pattern: /static/** freemarker: suffix: .ftl charset: UTF-8 check-template-location: true content-type: text/html template-loader-path: classpath:/templates/ server: port: 8012 # 分布式ID配置 distributed: id: # 如果是snowflake 相当于zk里面的namespace 如果segment没啥用 name: ${spring.application.name} segment: # 是否开启 segment enable: true url: jdbc:mysql://localhost:3306/distributed?useSSL=false&useUnicode=true&characterEncoding=utf8&useSSL=false&useTimezone=true&serverTimezone=GMT%2B8 username: root password: 123456 snowflake: enable: true # zk地址 zkPath: localhost:2181,localhost:2182,localhost:2183 # sessionTimeoutMs sessionTimeoutMs: 20000 # sessionTimeoutMs connectionTimeoutMs: 2000 ``` #### 使用示例 ```java class AppTest{ public static void main(String[] args){ // segment OkHttpClient client = new OkHttpClient().newBuilder() .build(); Request request = new Request.Builder() .url("http://localhost:8012/api/segment/get/distributed-test") .method("GET", null) .addHeader("Cookie", "oschina_new_user=false; user_locale=zh-CN") .build(); Response response = client.newCall(request).execute(); // snowflake OkHttpClient client = new OkHttpClient().newBuilder() .build(); Request request = new Request.Builder() .url("http://localhost:8012/api/snowflake/get/distributed-test") .method("GET", null) .addHeader("Cookie", "oschina_new_user=false; user_locale=zh-CN") .build(); Response response = client.newCall(request).execute(); } } ``` #### 参与贡献 1.美团leaf[https://github.com/Meituan-Dianping/Leaf]