{"id":15294734,"url":"https://github.com/mxsm/rain","last_synced_at":"2025-08-01T11:34:53.779Z","repository":{"id":57721703,"uuid":"491525986","full_name":"mxsm/rain","owner":"mxsm","description":"Rain ID generator is a distributed ID generation system, easy to use, high performance, high availability. Segmented mode and snowflake algorithm mode are provided","archived":false,"fork":false,"pushed_at":"2022-11-03T11:26:01.000Z","size":181,"stargazers_count":21,"open_issues_count":2,"forks_count":9,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-07-18T03:50:08.269Z","etag":null,"topics":["distributed-systems","high-availability","msyql","snowflake","spring-boot","uid","uidgenerator"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mxsm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-12T13:30:10.000Z","updated_at":"2024-11-03T01:05:00.000Z","dependencies_parsed_at":"2022-09-26T21:50:22.658Z","dependency_job_id":null,"html_url":"https://github.com/mxsm/rain","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/mxsm/rain","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mxsm%2Frain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mxsm%2Frain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mxsm%2Frain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mxsm%2Frain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mxsm","download_url":"https://codeload.github.com/mxsm/rain/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mxsm%2Frain/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268215611,"owners_count":24214365,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["distributed-systems","high-availability","msyql","snowflake","spring-boot","uid","uidgenerator"],"created_at":"2024-09-30T17:06:32.239Z","updated_at":"2025-08-01T11:34:53.752Z","avatar_url":"https://github.com/mxsm.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rain\n\n[![Publish package to the Maven Central Repository and GitHub Packages](https://github.com/mxsm/rain/actions/workflows/maven-publish.yml/badge.svg?branch=main)](https://github.com/mxsm/rain/actions/workflows/maven-publish.yml)\n\nDistributed global ID generation service, ID generation is divided into two modes：\n\n- **segment**\n- **snowflake**\n\nHow to use see the following introduction.\n\n## Quick Start\n\n### 1. Install dependencies\n\n- JDK 11\n- MySQL8\n- Maven 3.8.5\n\n### 2. Database initialization\n\n#### 2.1 Create table\n\nRun the sql script to create the database and tables：\n\n```sql\nDROP DATABASE IF EXISTS `uidgenerator`;\nCREATE DATABASE `uidgenerator` ;\nuse `uidgenerator`;\n\nDROP TABLE IF EXISTS mxsm_allocation;\nCREATE TABLE `mxsm_allocation` (\n `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',\n `biz_code` varchar(128) COLLATE utf8mb4_general_ci NOT NULL COMMENT '业务编码(用户ID,使用业务方编码)',\n `max_id` bigint NOT NULL DEFAULT '1' COMMENT '最大值',\n `step` int NOT NULL COMMENT '步长',\n `description` varchar(255) COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '说明',\n `create_time` timestamp NOT NULL COMMENT '创建时间',\n `update_time` timestamp NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',\n PRIMARY KEY (`id`),\n UNIQUE KEY `biz_code_index` (`biz_code`) USING BTREE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;\n\nDROP TABLE IF EXISTS mxsm_snowfalke_node;\nCREATE TABLE `mxsm_snowfalke_node` (\n `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',\n `host_name` bigint NOT NULL COMMENT 'IP地址',\n `port` int NOT NULL DEFAULT '1' COMMENT '端口',\n `deploy_env_type` enum('ACTUAL','CONTAINER') COLLATE utf8mb4_general_ci DEFAULT 'ACTUAL' COMMENT '部署环境类型',\n `description` varchar(255) COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '说明',\n `create_time` timestamp NOT NULL COMMENT '创建时间',\n `update_time` timestamp NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',\n PRIMARY KEY (`id`),\n UNIQUE KEY `mix_index` (`host_name`,`port`) USING BTREE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;\n```\n\n## 3. rain deployment and start\n\n### 3.1  Via the provided package\n\n**Step 1：Download binary package**\n\nIt can be downloaded from the [latest stable release page](https://github.com/mxsm/rain/releases)  **`rain-server-1.0.1-SNAPSHOT.tar.gz`**\n\n```shell\ntar -zxvf rain-server-1.0.1-SNAPSHOT.tar.gz\ncd rain-server-1.0.1-SNAPSHOT/\n```\n\n**Step 2：Modify conf/application.properties**\n\nModify the database-related configuration in the application.properties configuration:\n\n```properties\nspring.datasource.url=jdbc:mysql://ip:port/uidgenerator?useUnicode=true\u0026characterEncoding=utf-8\nspring.datasource.username=xxx\nspring.datasource.password=xxxxx\n```\n\n\u003e Tips:  make sure the database address, name, port number, username, and password are correct.\n\n**Step 3：Start server**\n\n```shell\nsh bin/start.sh\n```\n\n![image-20220604145105893](https://raw.githubusercontent.com/mxsm/picture/main/blog/javase/jvmimage-20220604145105893.png)\n\n### 4. Segment mode UID generation configuration\n\nModify conf/application.properties\n\n| config                      | default value | explain                                                      |\n| --------------------------- | ------------- | ------------------------------------------------------------ |\n| mxsm.uid.segment.threshold  | 40            | In cache mode, when the local cache threshold is lower than or equal to 40%, the segment filling will be loaded to the database, and the value ranges from 0 to 100 |\n| mxsm.uid.segment.cache-size | 16            | Number of cached segments to load by default in cache mode   |\n\nThe size of threshold and cache-size affects the frequency of segment obtained from the data. If cache-size is set too large, it will cause a waste of UID when the project is stopped for maintenance. But the cache-size is large enough that bizCode is loaded in memory before it can continue serving in the event of a database crash。\n\n### 5. Snowflake pattern UID generation configuration\n\nModify conf/application.properties :\n\n| config                              | default value | explain                                                      |\n| ----------------------------------- | ------------- | ------------------------------------------------------------ |\n| mxsm.uid.snowflake.timestamp-bits   | 41            | The number of bits of timestamp for the snowflake algorithm  |\n| mxsm.uid.snowflake.machine-id-bits  | 10            | The number of bits in the machine id of the snowflake algorithm |\n| mxsm.uid.snowflake.sequence-bits    | 12            | The number of bits in the snowflake algorithm sequence number |\n| mxsm.uid.snowflake.container        | false         | Whether the deployment is containerized                      |\n| mxsm.uid.snowflake.time-bits-second | false         | timestamp Whether it is in seconds                           |\n| mxsm.uid.snowflake.epoch            | 2022-05-01    | timestamp The relative time in the format yyyy-MM-dd and before the current time |\n\ntimestamp-bits、machine-id-bits、sequence-bits三个位数和加起来要等于63。\n\n### 6. Java SDK\n\nmaven client dependence：\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.github.mxsm\u003c/groupId\u003e\n  \u003cartifactId\u003erain-uidgenerator-client\u003c/artifactId\u003e\n  \u003cversion\u003e${latest version}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nexample:\n\n```java\nUidClient client = UidClient.builder()\n            .setUidGeneratorServerUir(\"http://172.29.250.21:8080\") //设置服务地址\n            .setSegmentNum(10) //设置获取的segment数量\n            .setThreshold(20) //设置阈值\n            .isSegmentUidFromRemote(false) //设置是否直接从服务器通过Restful接口的方式获取\n            .build();\nlong uid = client.getSegmentUid(\"mxsm\");\nlong uidRemote = client.getSegmentUid(\"mxsm\", true);\nlong snowflake =  client.getSnowflakeUid();\n```\n\n\n\n## Source Code Quick Start\n\n**Step 1： clone code**\n\n```shell\ngit clone https://github.com/mxsm/rain.git\ncd rain\n```\n\n**Step 2：Modify application.properties in rain-uidgenerator-server**\n\n```properties\nspring.datasource.url=jdbc:mysql://ip:port/uidgenerator?useUnicode=true\u0026characterEncoding=utf-8\nspring.datasource.username=xxx\nspring.datasource.password=xxxxx\n```\n\n**Step 3：maven package server**\n\n```shell\nmvn clean package -DskipTests=true\n```\n\n**Step 4：Start server**\n\n```shell\njava -Xms1g -Xmx1g -jar ./rain-uidgenerator-server/target/rain-uidgenerator-server-1.0.1-SNAPSHOT.jar\n```\n\n## Documentation\n\n**TODO**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmxsm%2Frain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmxsm%2Frain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmxsm%2Frain/lists"}