Skip to content

Commit 3fdcf76

Browse files
committed
1.1.1 pre view
1 parent 268fe00 commit 3fdcf76

File tree

23 files changed

+382
-333
lines changed

23 files changed

+382
-333
lines changed

README.cn.md

Lines changed: 39 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
uid-generator-spring-boot
2+
uid-reactive-generator-spring
33
==========================
44

55
UidReactiveGenerator是Java实现的, 基于[Snowflake](https://github.com/twitter/snowflake)算法的支持响应式编程分布式唯一ID生成器。
@@ -22,63 +22,58 @@ UidReactiveGenerator是Java实现的, 基于[Snowflake](https://github.com/twitt
2222

2323
## 使用
2424

25-
### Maven
2625

2726
#### spring boot autoconfig 方式
2827

29-
当前版本:1.0.5
28+
#### Worker node ID by Spring Discover service(不需要数据库)
3029

3130
```xml
32-
33-
<!-- 根据你的项目环境 选择一种 worker node 分配方式 -->
34-
35-
<!-- 以下仅选一种即可,多了会冲突 -->
36-
37-
<!--mybatis jdbc -->
38-
<dependency>
39-
<groupId>cooperlyt.github.io</groupId>
40-
<artifactId>uid-generator-mybatis-jdbc-spring-boot-starter</artifactId>
41-
<version>${uid.version}</version>
42-
</dependency>
43-
44-
<!--mybatis r2dbc -->
45-
<dependency>
46-
<groupId>cooperlyt.github.io</groupId>
47-
<artifactId>uid-generator-mybatis-r2dbc-spring-boot-starter</artifactId>
48-
<version>${uid.version}</version>
49-
</dependency>
50-
51-
52-
<!--jpa jdbc -->
5331
<dependency>
54-
<groupId>cooperlyt.github.io</groupId>
55-
<artifactId>uid-generator-jap-jdbc-spring-boot-starter</artifactId>
56-
<version>${uid.version}</version>
32+
<groupId>io.github.cooperlyt</groupId>
33+
<artifactId>uid-reactive-generator-spring-cloud-starter-discovery</artifactId>
34+
<version>1.1.1</version>
5735
</dependency>
5836

59-
<!--jpa r2dbc -->
60-
<dependency>
61-
<groupId>cooperlyt.github.io</groupId>
62-
<artifactId>uid-generator-jpa-r2dbc-spring-boot-starter</artifactId>
63-
<version>${uid.version}</version>
64-
</dependency>
37+
...
38+
```
39+
NOTE: 仅在Consul下测试,其它发现服务器没有进行测试。
6540

66-
<!-- 选择相印的数据库驱动包 -->
67-
<!-- jdbc驱动 -->
68-
<dependency>
69-
<groupId>org.mariadb.jdbc</groupId>
70-
<artifactId>mariadb-java-client</artifactId>
71-
</dependency>
41+
#### Worker node ID by DB
7242

73-
<!-- r2dbc驱动 -->
43+
```xml
7444
<dependency>
75-
<groupId>org.mariadb</groupId>
76-
<artifactId>r2dbc-mariadb</artifactId>
77-
<version>1.1.3</version>
45+
<groupId>io.github.cooperlyt</groupId>
46+
<artifactId>uid-reactive-generator-db-spring-boot-starter</artifactId>
47+
<version>1.1.1</version>
7848
</dependency>
49+
```
50+
* Mybatis JDBC:
51+
```xml
52+
<dependency>
53+
<groupId>org.mybatis.spring.boot</groupId>
54+
<artifactId>mybatis-spring-boot-starter</artifactId>
55+
<version>2.3.0</version>
56+
</dependency>
57+
```
58+
* Mybatis R2DBC
7959

60+
参见 [reactive-mybatis-support](https://github.com/chenggangpro/reactive-mybatis-support)
61+
62+
* JPA JDBC:
63+
```xml
64+
<dependency>
65+
<groupId>org.springframework.boot</groupId>
66+
<artifactId>spring-boot-starter-data-jpa</artifactId>
67+
</dependency>
68+
```
69+
* JPA R2DBC
70+
```xml
71+
<dependency>
72+
<groupId>org.springframework.boot</groupId>
73+
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
74+
</dependency>
8075
```
81-
由于开发时Mybatis官方还不支持r2dbc所以使用了[reactive-mybatis-support](https://github.com/chenggangpro/reactive-mybatis-support)
76+
8277

8378

8479
### 数据库(可选)
@@ -98,49 +93,6 @@ PRIMARY KEY(ID)
9893
) COMMENT='DB WorkerID Assigner for UID Generator',ENGINE = INNODB;
9994
```
10095

101-
### spring boot 配置
102-
103-
#### jdbc 配置 (以mariadb为例)
104-
105-
```yml
106-
mybatis:
107-
configuration:
108-
default-fetch-size: 100
109-
default-statement-timeout: 30
110-
map-underscore-to-camel-case: true
111-
spring:
112-
datasource:
113-
driver-class-name: org.mariadb.jdbc.Driver
114-
url: jdbc:mariadb://127.0.0.1:3306/database?
115-
username: root
116-
password: ****
117-
```
118-
119-
#### r2dbc 配置
120-
121-
```yml
122-
123-
r2dbc:
124-
mybatis:
125-
mapper-locations: classpath:mapper/*.xml
126-
map-underscore-to-camel-case: true
127-
spring:
128-
r2dbc:
129-
mybatis:
130-
r2dbc-url: r2dbc:mariadb://127.0.0.1:3306/database
131-
username: root
132-
password: ****
133-
pool:
134-
max-idle-time: PT3M
135-
validation-query: SELECT 1 FROM DUAL
136-
initial-size: 1
137-
max-size: 3
138-
acquire-retry: 3
139-
validation-depth: REMOTE
140-
max-create-connection-time: PT30S
141-
142-
```
143-
14496
#### 自定义 CachedUidGenerator 拒绝策略
14597

14698
```java

README.md

Lines changed: 49 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
uid-generator-spring-boot-starter
2+
uid-reactive-generator-spring
33
==========================
44

55
[In Chinese 中文版](https://github.com/cooperlyt/uid-generator-spring-boot/blob/master/README.cn.md)
@@ -14,7 +14,8 @@ Based on [Snowflake](https://github.com/twitter/snowflake),[UidGenerator](http
1414
* Supported Reactive Programming,Return a `Mono<Long>`,
1515
* In CachedUidGenerator:When consumption rate is higher than refill rate,Notify subscribers in a non-blocking manner after waiting for the fill to complete.
1616
* In DefaultUidGenerator and not allow use future time state:Notify subscribers in a non-blocking way after the current time ID is exhausted and waits for the next second.
17-
* Supported mybatis jdbc, mybatis r2bc , jap jdbc , jap r2dbc
17+
* Supported get worker node id from db by mybatis jdbc, mybatis r2bc , jap jdbc , jap r2dbc
18+
* Supported get worker node id from Spring Discovery service
1819

1920

2021
## Principle and performance
@@ -23,150 +24,74 @@ Refer [Snowflake](https://github.com/twitter/snowflake) and [UidGenerator](https
2324

2425
## Usage
2526

26-
### Maven
27+
### For Spring boot autoconfig
2728

28-
#### for Spring boot autoconfig
29-
30-
Current version is:1.0.5
29+
#### Worker node ID by Spring Discover service(not need databases)
3130

3231
```xml
33-
34-
<!-- Choose one and only on -->
35-
36-
37-
<!--mybatis jdbc -->
38-
<dependency>
39-
<groupId>cooperlyt.github.io</groupId>
40-
<artifactId>uid-generator-mybatis-jdbc-spring-boot-starter</artifactId>
41-
<version>${uid.version}</version>
42-
</dependency>
43-
44-
<!--mybatis r2dbc -->
4532
<dependency>
46-
<groupId>cooperlyt.github.io</groupId>
47-
<artifactId>uid-generator-mybatis-r2dbc-spring-boot-starter</artifactId>
48-
<version>${uid.version}</version>
33+
<groupId>io.github.cooperlyt</groupId>
34+
<artifactId>uid-reactive-generator-spring-cloud-starter-discovery</artifactId>
35+
<version>1.1.1</version>
4936
</dependency>
5037

38+
...
39+
```
40+
NOTE: only test on Consul
5141

52-
<!--jpa jdbc -->
53-
<dependency>
54-
<groupId>cooperlyt.github.io</groupId>
55-
<artifactId>uid-generator-jap-jdbc-spring-boot-starter</artifactId>
56-
<version>${uid.version}</version>
57-
</dependency>
58-
59-
<!--jpa r2dbc -->
60-
<dependency>
61-
<groupId>cooperlyt.github.io</groupId>
62-
<artifactId>uid-generator-jpa-r2dbc-spring-boot-starter</artifactId>
63-
<version>${uid.version}</version>
64-
</dependency>
65-
66-
<!-- example for mariadb database driver-->
67-
<!-- jdbc -->
68-
<dependency>
69-
<groupId>org.mariadb.jdbc</groupId>
70-
<artifactId>mariadb-java-client</artifactId>
71-
</dependency>
42+
#### Worker node ID by DB
7243

73-
<!-- r2dbc -->
44+
```xml
7445
<dependency>
75-
<groupId>org.mariadb</groupId>
76-
<artifactId>r2dbc-mariadb</artifactId>
77-
<version>1.1.3</version>
46+
<groupId>io.github.cooperlyt</groupId>
47+
<artifactId>uid-reactive-generator-db-spring-boot-starter</artifactId>
48+
<version>1.1.1</version>
7849
</dependency>
79-
50+
```
51+
* Mybatis JDBC:
52+
```xml
53+
<dependency>
54+
<groupId>org.mybatis.spring.boot</groupId>
55+
<artifactId>mybatis-spring-boot-starter</artifactId>
56+
<version>2.3.0</version>
57+
</dependency>
58+
```
59+
* Mybatis R2DBC
60+
Refer [reactive-mybatis-support](https://github.com/chenggangpro/reactive-mybatis-support)
61+
* JPA JDBC:
62+
```xml
63+
<dependency>
64+
<groupId>org.springframework.boot</groupId>
65+
<artifactId>spring-boot-starter-data-jpa</artifactId>
66+
</dependency>
67+
```
68+
* JPA R2DBC
69+
```xml
70+
<dependency>
71+
<groupId>org.springframework.boot</groupId>
72+
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
73+
</dependency>
8074
```
8175

8276

83-
### Databases(optional)
84-
Table WORKER_NODE scrip:
77+
* Databases scrip:
8578
```sql
8679
DROP TABLE IF EXISTS WORKER_NODE;
8780
CREATE TABLE WORKER_NODE
8881
(
89-
ID BIGINT NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
90-
HOST_NAME VARCHAR(64) NOT NULL COMMENT 'host name',
91-
PORT VARCHAR(64) NOT NULL COMMENT 'port',
92-
TYPE INT NOT NULL COMMENT 'node type: CONTAINER(1), ACTUAL(2), FAKE(3)',
93-
LAUNCH_DATE DATE NOT NULL COMMENT 'launch date',
94-
MODIFIED TIMESTAMP NOT NULL COMMENT 'modified time',
95-
CREATED TIMESTAMP NOT NULL COMMENT 'created time',
96-
PRIMARY KEY(ID)
82+
ID BIGINT NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
83+
HOST VARCHAR(64) NOT NULL COMMENT 'host name',
84+
PORT VARCHAR(64) NOT NULL COMMENT 'port',
85+
TYPE INT NOT NULL COMMENT 'node type: CONTAINER(1), ACTUAL(2), FAKE(3)',
86+
LAUNCH DATE NOT NULL COMMENT 'launch date',
87+
MODIFIED TIMESTAMP NOT NULL COMMENT 'modified time',
88+
CREATED TIMESTAMP NOT NULL COMMENT 'created time',
89+
PRIMARY KEY(ID)
9790
) COMMENT='DB WorkerID Assigner for UID Generator',ENGINE = INNODB;
9891
```
9992

100-
### spring boot configure
101-
102-
Example for mariadb
103-
104-
#### mybatis jdbc
105-
106-
```yml
107-
mybatis:
108-
configuration:
109-
default-fetch-size: 100
110-
default-statement-timeout: 30
111-
map-underscore-to-camel-case: true
112-
spring:
113-
datasource:
114-
driver-class-name: org.mariadb.jdbc.Driver
115-
url: jdbc:mariadb://127.0.0.1:3306/database?
116-
username: root
117-
password: ****
118-
```
119-
120-
#### mybatis r2dbc
121-
refer [reactive-mybatis-support](https://github.com/chenggangpro/reactive-mybatis-support)
122-
```yml
123-
124-
r2dbc:
125-
mybatis:
126-
mapper-locations: classpath:mapper/*.xml
127-
map-underscore-to-camel-case: true
128-
spring:
129-
r2dbc:
130-
mybatis:
131-
r2dbc-url: r2dbc:mariadb://127.0.0.1:3306/database
132-
username: root
133-
password: ****
134-
pool:
135-
max-idle-time: PT3M
136-
validation-query: SELECT 1 FROM DUAL
137-
initial-size: 1
138-
max-size: 3
139-
acquire-retry: 3
140-
validation-depth: REMOTE
141-
max-create-connection-time: PT30S
142-
```
143-
144-
#### jpa jdbc
145-
146-
```yml
147-
spring:
148-
jpa:
149-
show-sql: true
150-
datasource:
151-
driver-class-name: org.mariadb.jdbc.Driver
152-
url: jdbc:mariadb://127.0.0.1:3306/corp?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&allowMultiQueries=true
153-
username: root
154-
password: ****
155-
```
156-
157-
#### jpa r2dbc
15893

159-
```yml
16094

161-
spring:
162-
r2dbc:
163-
url: r2dbc:mariadb://127.0.0.1:3306/corp?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false
164-
username: root
165-
password: ****
166-
# pool:
167-
# initial-size: 11
168-
169-
```
17095

17196

17297
#### CachedUidGenerator rejected handler(optional)

0 commit comments

Comments
 (0)