1
0
mirror of synced 2026-04-19 06:48:39 +08:00

auto commit

This commit is contained in:
yitter
2021-06-22 18:20:23 +08:00
parent 4a0a1f64b8
commit 7f902f70cd
2 changed files with 39 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
@echo off
cargo build --release
@rem cargo build --release --target i686-pc-windows-msvc
@pause

View File

@@ -2,7 +2,43 @@
## 关于AutoRegisterWorkerId
自动注册 WorkerId 参考:
https://gitee.com/yitter/idgenerator#%E8%87%AA%E5%8A%A8%E6%B3%A8%E5%86%8Cworkerid
## 自动注册WorkerId
🔍 唯一ID生成器依赖WorkerId当业务服务需要水平无差别复制自动扩容这就要求能自动注册全局唯一WorkerId然后才能生产唯一ID。
🔍 本算法提供开源动态库go语言实现能在容器 k8s 等容器环境下,通过 redis 自动注册 WorkerId。
🔍 通过redis注册WorkerId并非唯一方法。你还可以开发中心化的配置服务各端点服务启动时通过中心服务获取唯一 WorkerId。
🔍 当然如果你的服务无需自动扩容那就不必自动注册WorkerId而是为它们分别设置全局唯一值。
🔍 发挥你的想象力方法还有很多。此处抛砖引玉开发中心化的ID生成服务由它为各端点服务单个或批量生成可用ID。
#### 自动注册流程图
图片链接https://github.com/yitter/IdGenerator/blob/master/Tools/AutoRegisterWorkerId/regprocess.jpg
源码路径:/Go/source/regworkerid/reghelper.go
#### 动态库下载
下载链接https://github.com/yitter/IdGenerator/releases/download/reg_v1.0/regworkerid_lib_v1.0.zip
#### 动态库接口定义
```
// 注册一个 WorkerId会先注销所有本机已注册的记录
// ip: redis 服务器地址
// port: redis 端口
// password: redis 访问密码,可为空字符串“”
// maxWorkerId: 最大 WorkerId
extern GoInt32 RegisterOne(char* ip, GoInt32 port, char* password, GoInt32 maxWorkerId);
// 注销本机已注册的 WorkerId
extern void UnRegister();
// 检查本地WorkerId是否有效0-有效,其它-无效)
extern GoInt32 Validate(GoInt32 workerId);
```