mirror of
https://github.com/dataease/dataease.git
synced 2026-05-15 05:22:13 +08:00
fix(X-Pack): 集群多节点 ID 冲突,增加配置机器 ID
This commit is contained in:
committed by
fit2cloud-chenyw
parent
9ba4057f40
commit
d463bd8282
@@ -1,12 +1,21 @@
|
||||
package io.dataease.utils;
|
||||
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class IDUtils {
|
||||
|
||||
private static SnowFlake snowFlake = new SnowFlake(1, 1);
|
||||
|
||||
private static SnowFlake snowFlake;
|
||||
|
||||
@Resource
|
||||
public void setSnowFlake(SnowFlake snowFlake) {
|
||||
IDUtils.snowFlake = snowFlake;
|
||||
}
|
||||
|
||||
public static String randomID(Integer num) {
|
||||
num = ObjectUtils.isEmpty(num) ? 16 : num;
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
package io.dataease.utils;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SnowFlake {
|
||||
|
||||
|
||||
@Value("${dataease.machine-id:1}")
|
||||
public void setMachineId(long machineId) {
|
||||
this.machineId = machineId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 起始的时间戳
|
||||
*/
|
||||
@@ -44,6 +54,10 @@ public class SnowFlake {
|
||||
this.machineId = machineId;
|
||||
}
|
||||
|
||||
public SnowFlake() {
|
||||
this.datacenterId = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 产生下一个ID
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user