# snowflake **Repository Path**: javashop/snowflake ## Basic Information - **Project Name**: snowflake - **Description**: 基于Snowflake算法的发号器,k8s容器化扩容时唯一的机器Id生成的解决方案,集成在spring boot的示例 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: http://www.javamall.com.cn - **GVP Project**: No ## Statistics - **Stars**: 9 - **Forks**: 9 - **Created**: 2020-04-17 - **Last Updated**: 2022-08-09 ## Categories & Tags **Categories**: distributed-service **Tags**: None ## README # snowflake sn creater #### Introduction The issuer based on the Snowflake algorithm includes an example integrated in spring boot. This code is suitable for embedding the issuer inside the application, rather than the independent generator app. ![image-20200420120645877](README.assets/image-20200420120645877.png) #### Focus Using Snowflake algorithm, the main purpose is to solve the generation of machine id. Especially in the deployment based on containers (docker, k8s), etc., the automatic expansion machine ID is automatically generated and the guarantee of uniqueness. ![image-20200420121044889](README.assets/image-20200420121044889.png) #### Ideas The difficulty is that expansion is the creation of multiple instances of an app. The app passed in registers itself in redis when it starts, and there is a heartbeat at the same time, regularly reporting its survival to redis. If it hangs, clear your own instance in reids and calculate the workid according to the instance. #### use ~~~java @Autowired SnCreator snCreator; public String test() { String id = snCreator.create(1); return id; } ~~~ create have one paramter:sub code [Javashop open source product] (https://www.javamall.com.cn)