一. 概念
1. msgId(uniqId)
由 producer客户端 生成,调用方法MessageClientIDSetter.createUniqID()生成全局唯一的Id
private static final int LEN;
private static final String FIX_STRING;
private static final AtomicInteger COUNTER;
private static long startTime;
private static long nextStartTime;
public static String createUniqID() {
StringBuilder sb = new StringBuilder(LEN * 2);
sb.append(FIX_STRING); // 固定值,程序启动时生成
sb.append(UtilAll.bytes2string(createUniqIDBuffer())); // 变化值 根据时间差+自增长生成
return sb.toString();
}
- FIX_STRING 固定前缀
- 生成规则:客户端的IP、进程ID、MessageClientIDSetter类加载器的hashcode
static {
byte[] ip;
try {
ip = UtilAll.getIP();
} catch (Exception e) {
ip = createFakeIP();
}
LEN = ip.length + 2 + 4 + 4 + 2;
ByteBuffer tempBuffer = ByteBuffer.allocate(ip.length + 2 + 4);
tempBuffer.put(ip); // 客户端IP
tempBuffer.putShort((short) UtilAll.getPid()); // 进程ID
tempBuffer.putInt