Skip to content

Commit 268fe00

Browse files
committed
combine db worker node id
1 parent ab4817b commit 268fe00

File tree

68 files changed

+929
-1039
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+929
-1039
lines changed

.idea/encodings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/sqlDataSources.xml

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/sqldialects.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/pom.xml

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>io.github.cooperlyt</groupId>
8+
<artifactId>uid-reactive-generator-spring</artifactId>
9+
<version>1.0.6-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>example</artifactId>
13+
14+
<properties>
15+
<maven.compiler.source>15</maven.compiler.source>
16+
<maven.compiler.target>15</maven.compiler.target>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
</properties>
19+
20+
<dependencyManagement>
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.cloud</groupId>
24+
<artifactId>spring-cloud-dependencies</artifactId>
25+
<version>2021.0.5</version>
26+
<type>pom</type>
27+
<scope>import</scope>
28+
</dependency>
29+
</dependencies>
30+
</dependencyManagement>
31+
32+
<dependencies>
33+
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-logging</artifactId>
37+
</dependency>
38+
39+
40+
<!-- test spring web -->
41+
42+
<dependency>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-starter-webflux</artifactId>
45+
</dependency>
46+
47+
48+
<!-- test spring cloud -->
49+
<dependency>
50+
<groupId>org.springframework.cloud</groupId>
51+
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
52+
53+
<exclusions>
54+
<!-- ribbon 已经在新版本中被弃用, 被 Spring Cloud Loadbalancer 替换-->
55+
<exclusion>
56+
<groupId>org.springframework.cloud</groupId>
57+
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
58+
</exclusion>
59+
</exclusions>
60+
</dependency>
61+
62+
<dependency>
63+
<groupId>org.springframework.cloud</groupId>
64+
<artifactId>spring-cloud-gateway-webflux</artifactId>
65+
</dependency>
66+
67+
<dependency>
68+
<groupId>org.springframework.boot</groupId>
69+
<artifactId>spring-boot-starter-actuator</artifactId>
70+
</dependency>
71+
72+
<dependency>
73+
<groupId>org.springframework.cloud</groupId>
74+
<artifactId>spring-cloud-starter-consul-config</artifactId>
75+
</dependency>
76+
77+
<!-- db worker node id -->
78+
79+
<dependency>
80+
<groupId>io.github.cooperlyt</groupId>
81+
<artifactId>uid-reactive-generator-db-spring-boot-starter</artifactId>
82+
<version>1.0.6-SNAPSHOT</version>
83+
</dependency>
84+
85+
<!-- jdbc -->
86+
87+
<!-- <dependency>-->
88+
<!-- <groupId>org.mariadb.jdbc</groupId>-->
89+
<!-- <artifactId>mariadb-java-client</artifactId>-->
90+
<!-- <scope>test</scope>-->
91+
<!-- </dependency>-->
92+
93+
<!-- jpa jdbc -->
94+
95+
<!-- <dependency>-->
96+
<!-- <groupId>org.springframework.boot</groupId>-->
97+
<!-- <artifactId>spring-boot-starter-data-jpa</artifactId>-->
98+
<!-- </dependency>-->
99+
100+
<!-- mybatis jdbc -->
101+
102+
<dependency>
103+
<groupId>org.mybatis.spring.boot</groupId>
104+
<artifactId>mybatis-spring-boot-starter</artifactId>
105+
<version>2.3.0</version>
106+
</dependency>
107+
108+
109+
110+
<!-- r2dbc -->
111+
112+
<dependency>
113+
<groupId>org.mariadb</groupId>
114+
<artifactId>r2dbc-mariadb</artifactId>
115+
</dependency>
116+
117+
<dependency>
118+
<groupId>org.springframework.boot</groupId>
119+
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
120+
</dependency>
121+
122+
123+
<!-- mybatis r2dbc -->
124+
<dependency>
125+
<groupId>pro.chenggang</groupId>
126+
<artifactId>mybatis-r2dbc-spring</artifactId>
127+
<version>1.2.5.RELEASE</version>
128+
</dependency>
129+
130+
131+
132+
<dependency>
133+
<groupId>io.projectreactor</groupId>
134+
<artifactId>reactor-test</artifactId>
135+
<scope>test</scope>
136+
</dependency>
137+
138+
139+
</dependencies>
140+
141+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.github.cooperlyt.cloud.uid;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Application {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(Application.class, args);
11+
}
12+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
2+
server:
3+
port: 19005
4+
#Setting the logging levels for the service
5+
spring:
6+
application:
7+
name: uid-example
8+
profiles:
9+
active: mybatis-r2dbc
10+
cloud:
11+
loadbalancer:
12+
ribbon:
13+
enabled: false
14+
consul:
15+
ribbon:
16+
enabled: false
17+
discovery:
18+
serviceName: ${spring.application.name}
19+
# 启用服务发现
20+
enabled: true
21+
# 启用服务注册
22+
register: true
23+
# 服务停止时取消注册
24+
deregister: true
25+
# 表示注册时使用IP而不是hostname
26+
prefer-ip-address: true
27+
# 执行监控检查的频率
28+
health-check-interval: 30s
29+
# 设置健康检查失败多长时间后,取消注册
30+
health-check-critical-timeout: 30s
31+
# 健康检查的路径
32+
health-check-path: /actuator/info
33+
# 服务注册标识,格式为:应用名称+服务器IP+端口
34+
instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}:${server.port}
35+
host: 127.0.0.1
36+
port: 8500
37+
sql:
38+
init:
39+
mode: never
40+
41+
#开启actuator管理api
42+
management:
43+
endpoints:
44+
web:
45+
exposure:
46+
include: '*'
47+
endpoint:
48+
health:
49+
show-details: always
50+
51+
logging:
52+
level:
53+
pro.chenggang: DEBUG
54+
org.springframework.r2dbc: DEBUG
55+
io.github.cooperlyt: DEBUG
56+
57+
#pagehelper:
58+
# helperDialect: mariadb
59+
# reasonable: true
60+
# supportMethodsArguments: true
61+
# params: count=countSql
62+
63+
64+
65+
# 以下为可选配置, 如未指定将采用默认值
66+
uid:
67+
timeBits: 30 # 时间位, 默认:30
68+
workerBits: 16 # 机器位, 默认:16
69+
seqBits: 7 # 序列号, 默认:7
70+
epochStr: "2023-02-10" # 初始时间, 默认:"2019-02-20"
71+
maxBackwardSeconds: 1 # 时钟回拨最长容忍时间(秒), 默认:1
72+
enableFutureTime: false # 允许使用未来时间生成ID, 默认: false
73+
CachedUidGenerator: # CachedUidGenerator相关参数
74+
boostPower: 3 # RingBuffer size扩容参数, 可提高UID生成的吞吐量, 默认:3
75+
paddingFactor: 50 # 指定何时向RingBuffer中填充UID, 取值为百分比(0, 100), 默认为50
76+
#scheduleInterval: 60 # 默认:不配置此项, 即不实用Schedule线程. 如需使用, 请指定Schedule线程时间间隔, 单位:秒
77+
78+
---
79+
80+
spring:
81+
config:
82+
activate:
83+
on-profile: jdbc
84+
85+
import: optional:consul:${spring.cloud.consul.host}:${spring.cloud.consul.port}
86+
datasource:
87+
url: "jdbc:mariadb://127.0.0.1:3306/corp?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&allowMultiQueries=true"
88+
username: "root"
89+
password: "5257mq"
90+
91+
---
92+
93+
spring:
94+
config:
95+
activate:
96+
on-profile: mybatis-r2dbc
97+
98+
import: optional:consul:${spring.cloud.consul.host}:${spring.cloud.consul.port}
99+
r2dbc:
100+
mybatis:
101+
r2dbc-url: r2dbc:mariadb://127.0.0.1:3306/corp?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false
102+
username: root
103+
password: 5257mq
104+
pool:
105+
max-idle-time: PT3M
106+
validation-query: SELECT 1 FROM DUAL
107+
initial-size: 1
108+
max-size: 3
109+
acquire-retry: 3
110+
validation-depth: REMOTE
111+
max-create-connection-time: PT30S
112+
r2dbc:
113+
mybatis:
114+
map-underscore-to-camel-case: true
115+
116+
---
117+
spring:
118+
config:
119+
activate:
120+
on-profile: jpa-r2dbc
121+
122+
import: optional:consul:${spring.cloud.consul.host}:${spring.cloud.consul.port}
123+
r2dbc:
124+
url: "r2dbc:mariadb://127.0.0.1:3306/corp?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&allowMultiQueries=true"
125+
username: root
126+
password: 5257mq
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.github.cooperlyt.cloud.uid.impl.CachedUidGenerator;
44
import org.apache.commons.lang.StringUtils;
5+
import org.junit.jupiter.api.Assertions;
56
import org.junit.jupiter.api.Disabled;
67
import org.junit.jupiter.api.Test;
78
import org.junit.jupiter.api.extension.ExtendWith;
@@ -116,7 +117,7 @@ private void doGenerate(Set<Long> uidSet, int index) {
116117

117118
// Check UID is positive, and can be parsed
118119
assertTrue(uid > 0L);
119-
assertTrue(StringUtils.isNotBlank(parsedInfo));
120+
Assertions.assertTrue(StringUtils.isNotBlank(parsedInfo));
120121

121122
if (VERBOSE) {
122123
System.out.println(Thread.currentThread().getName() + " No." + index + " >>> " + parsedInfo);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.github.cooperlyt.cloud.uid.impl.DefaultUidGenerator;
44
import org.apache.commons.lang.StringUtils;
5+
import org.junit.jupiter.api.Assertions;
56
import org.junit.jupiter.api.Disabled;
67
import org.junit.jupiter.api.Test;
78
import org.junit.jupiter.api.extension.ExtendWith;
@@ -115,7 +116,7 @@ private void doGenerate(Set<Long> uidSet, int index) {
115116

116117
// Check UID is positive, and can be parsed
117118
assertTrue(uid > 0L);
118-
assertTrue(StringUtils.isNotBlank(parsedInfo));
119+
Assertions.assertTrue(StringUtils.isNotBlank(parsedInfo));
119120

120121
if (VERBOSE) {
121122
System.out.println(Thread.currentThread().getName() + " No." + index + " >>> " + parsedInfo);

0 commit comments

Comments
 (0)