集成百度UID生成

This commit is contained in:
WangHao 2020-09-09 21:31:37 +08:00
parent d3b5496aba
commit a1e23ed9c9
5 changed files with 74 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package com.ruoyi.web.test.controller;
import com.github.wujun234.uid.UidGenerator;
import com.ruoyi.bookmark.mapper.SqMenuMapper;
import com.ruoyi.bookmark.service.ISqUserTagService;
import com.ruoyi.web.controller.yunbookmark.SqBookmarkController;
@ -10,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@ -79,4 +81,7 @@ public class SqBookmarkTest extends BaseSpringBootTest{
}

View File

@ -0,0 +1,37 @@
package com.ruoyi.web.test.controller;
import com.github.wujun234.uid.UidGenerator;
import org.junit.Test;
import javax.annotation.Resource;
/**
* @Auther: Wang
* @Date: 2020/09/09 21:21
* 功能描述:
*/
public class UIDTest extends BaseSpringBootTest{
@Resource
private UidGenerator defaultUidGenerator;
@Resource
private UidGenerator cachedUidGenerator;
@Test
public void testSerialGenerate() {
// Generate UID
long cachedUidGeneratoruid = cachedUidGenerator.getUID();
long defaultUidGeneratoruid = defaultUidGenerator.getUID();
System.out.println("cachedUidGeneratoruid:"+cachedUidGeneratoruid);
System.out.println("cachedUidGeneratoruid解密:"+cachedUidGenerator.parseUID(cachedUidGeneratoruid));
System.out.println("defaultUidGeneratoruid:"+defaultUidGeneratoruid);
System.out.println("defaultUidGeneratoruid解密:"+cachedUidGenerator.parseUID(defaultUidGeneratoruid));
// Parse UID into [Timestamp, WorkerId, Sequence]
// {"UID":"450795408770","timestamp":"2019-02-20 14:55:39","workerId":"27","sequence":"2"}
// System.out.println(cachedUidGenerator.parseUID(uid));
}
}

View File

@ -125,3 +125,24 @@ xss:
excludes: /system/notice/*
# 匹配链接
urlPatterns: /system/*,/monitor/*,/tool/*
# 关于UID比特分配的建议
# 对于并发数要求不高、期望长期使用的应用, 可增加timeBits位数, 减少seqBits位数. 例如节点采取用完即弃的WorkerIdAssigner策略, 重启频率为12次/天, 那么配置成{"workerBits":23,"timeBits":31,"seqBits":9}时, 可支持28个节点以整体并发量14400 UID/s的速度持续运行68年.
#
# 对于节点重启频率频繁、期望长期使用的应用, 可增加workerBits和timeBits位数, 减少seqBits位数. 例如节点采取用完即弃的WorkerIdAssigner策略, 重启频率为24*12次/天, 那么配置成{"workerBits":27,"timeBits":30,"seqBits":6}时, 可支持37个节点以整体并发量2400 UID/s的速度持续运行34年.
#百度UID
uid:
timeBits: 31 # 时间位, 默认:30
workerBits: 23 # 机器位, 默认:16
seqBits: 9 # 序列号, 默认:7
epochStr: "2020-09-01" # 初始时间, 默认:"2019-02-20"
enableBackward: true # 是否容忍时钟回拨, 默认:true
maxBackwardSeconds: 1 # 时钟回拨最长容忍时间(秒), 默认:1
CachedUidGenerator: # CachedUidGenerator相关参数
boostPower: 3 # RingBuffer size扩容参数, 可提高UID生成的吞吐量, 默认:3
paddingFactor: 50 # 指定何时向RingBuffer中填充UID, 取值为百分比(0, 100), 默认为50
#scheduleInterval: 60 # 默认:不配置此项, 即不实用Schedule线程. 如需使用, 请指定Schedule线程时间间隔, 单位:秒

View File

@ -149,6 +149,12 @@
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
</dependency>
<!--百度UID生成-->
<dependency>
<groupId>com.github.wujun234</groupId>
<artifactId>uid-generator-spring-boot-starter</artifactId>
<version>1.0.2.RELEASE</version>
</dependency>
</dependencies>

View File

@ -3,12 +3,15 @@ package com.ruoyi.bookmark.service.impl;
import java.util.List;
import java.util.Map;
import com.github.wujun234.uid.UidGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.bookmark.mapper.SqUserTagMapper;
import com.ruoyi.bookmark.domain.SqUserTag;
import com.ruoyi.bookmark.service.ISqUserTagService;
import javax.annotation.Resource;
/**
* 标签管理Service业务层处理
*
@ -22,6 +25,8 @@ public class SqUserTagServiceImpl implements ISqUserTagService
private SqUserTagMapper sqUserTagMapper;
/**
* 批量减少用戶 标签引用的 数量 -1
*