public class DisposableWorkerIdAssigner extends Object implements WorkerIdAssigner
WorkerIdAssigner,
the worker id will be discarded after assigned to the UidGenerator
基于DB自增的worker id 分配器的实现
SnowFlake中,deltaSeconds依赖时间戳,可以通过系统获取;sequence可以通过自增来控制;这俩字段都是项目可以自给自足的,而WorkerId则必须还有一个策略来提供。 这个策略要保证每次服务启动的时候拿到的WorkerId都能不重复,不然就有可能集群不同的机器拿到不同的workerid,会发重复的号了; 而服务启动又是个相对低频的行为,也不影响发号性能,所以可以用DB自增ID来实现。 DatabaseWorkerIdAssigner就是依赖DB自增ID实现的workerId分配器。
@Transactional(rollbackFor=java.lang.Exception.class) public long assignWorkerId()
If there is host name & port in the environment, we considered that the node runs in Docker container
Otherwise, the node runs on an actual machine.
assignWorkerId 在接口中 WorkerIdAssignerCopyright © 2023. All rights reserved.