Skip to content

Commit

Permalink
1.1.1 pre view
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperlyt committed Feb 22, 2023
1 parent 268fe00 commit 3fdcf76
Show file tree
Hide file tree
Showing 23 changed files with 382 additions and 333 deletions.
126 changes: 39 additions & 87 deletions README.cn.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

uid-generator-spring-boot
uid-reactive-generator-spring
==========================

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

## 使用

### Maven

#### spring boot autoconfig 方式

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

```xml

<!-- 根据你的项目环境 选择一种 worker node 分配方式 -->

<!-- 以下仅选一种即可,多了会冲突 -->

<!--mybatis jdbc -->
<dependency>
<groupId>cooperlyt.github.io</groupId>
<artifactId>uid-generator-mybatis-jdbc-spring-boot-starter</artifactId>
<version>${uid.version}</version>
</dependency>

<!--mybatis r2dbc -->
<dependency>
<groupId>cooperlyt.github.io</groupId>
<artifactId>uid-generator-mybatis-r2dbc-spring-boot-starter</artifactId>
<version>${uid.version}</version>
</dependency>


<!--jpa jdbc -->
<dependency>
<groupId>cooperlyt.github.io</groupId>
<artifactId>uid-generator-jap-jdbc-spring-boot-starter</artifactId>
<version>${uid.version}</version>
<groupId>io.github.cooperlyt</groupId>
<artifactId>uid-reactive-generator-spring-cloud-starter-discovery</artifactId>
<version>1.1.1</version>
</dependency>

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

<!-- 选择相印的数据库驱动包 -->
<!-- jdbc驱动 -->
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
</dependency>
#### Worker node ID by DB

<!-- r2dbc驱动 -->
```xml
<dependency>
<groupId>org.mariadb</groupId>
<artifactId>r2dbc-mariadb</artifactId>
<version>1.1.3</version>
<groupId>io.github.cooperlyt</groupId>
<artifactId>uid-reactive-generator-db-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
```
* Mybatis JDBC:
```xml
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.3.0</version>
</dependency>
```
* Mybatis R2DBC

参见 [reactive-mybatis-support](https://github.com/chenggangpro/reactive-mybatis-support)

* JPA JDBC:
```xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
```
* JPA R2DBC
```xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
</dependency>
```
由于开发时Mybatis官方还不支持r2dbc所以使用了[reactive-mybatis-support](https://github.com/chenggangpro/reactive-mybatis-support)



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

### spring boot 配置

#### jdbc 配置 (以mariadb为例)

```yml
mybatis:
configuration:
default-fetch-size: 100
default-statement-timeout: 30
map-underscore-to-camel-case: true
spring:
datasource:
driver-class-name: org.mariadb.jdbc.Driver
url: jdbc:mariadb://127.0.0.1:3306/database?
username: root
password: ****
```
#### r2dbc 配置
```yml

r2dbc:
mybatis:
mapper-locations: classpath:mapper/*.xml
map-underscore-to-camel-case: true
spring:
r2dbc:
mybatis:
r2dbc-url: r2dbc:mariadb://127.0.0.1:3306/database
username: root
password: ****
pool:
max-idle-time: PT3M
validation-query: SELECT 1 FROM DUAL
initial-size: 1
max-size: 3
acquire-retry: 3
validation-depth: REMOTE
max-create-connection-time: PT30S

```

#### 自定义 CachedUidGenerator 拒绝策略

```java
Expand Down
173 changes: 49 additions & 124 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

uid-generator-spring-boot-starter
uid-reactive-generator-spring
==========================

[In Chinese 中文版](https://github.com/cooperlyt/uid-generator-spring-boot/blob/master/README.cn.md)
Expand All @@ -14,7 +14,8 @@ Based on [Snowflake](https://github.com/twitter/snowflake),[UidGenerator](http
* Supported Reactive Programming,Return a `Mono<Long>`,
* In CachedUidGenerator:When consumption rate is higher than refill rate,Notify subscribers in a non-blocking manner after waiting for the fill to complete.
* 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.
* Supported mybatis jdbc, mybatis r2bc , jap jdbc , jap r2dbc
* Supported get worker node id from db by mybatis jdbc, mybatis r2bc , jap jdbc , jap r2dbc
* Supported get worker node id from Spring Discovery service


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

## Usage

### Maven
### For Spring boot autoconfig

#### for Spring boot autoconfig

Current version is:1.0.5
#### Worker node ID by Spring Discover service(not need databases)

```xml

<!-- Choose one and only on -->


<!--mybatis jdbc -->
<dependency>
<groupId>cooperlyt.github.io</groupId>
<artifactId>uid-generator-mybatis-jdbc-spring-boot-starter</artifactId>
<version>${uid.version}</version>
</dependency>

<!--mybatis r2dbc -->
<dependency>
<groupId>cooperlyt.github.io</groupId>
<artifactId>uid-generator-mybatis-r2dbc-spring-boot-starter</artifactId>
<version>${uid.version}</version>
<groupId>io.github.cooperlyt</groupId>
<artifactId>uid-reactive-generator-spring-cloud-starter-discovery</artifactId>
<version>1.1.1</version>
</dependency>

...
```
NOTE: only test on Consul

<!--jpa jdbc -->
<dependency>
<groupId>cooperlyt.github.io</groupId>
<artifactId>uid-generator-jap-jdbc-spring-boot-starter</artifactId>
<version>${uid.version}</version>
</dependency>

<!--jpa r2dbc -->
<dependency>
<groupId>cooperlyt.github.io</groupId>
<artifactId>uid-generator-jpa-r2dbc-spring-boot-starter</artifactId>
<version>${uid.version}</version>
</dependency>

<!-- example for mariadb database driver-->
<!-- jdbc -->
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
</dependency>
#### Worker node ID by DB

<!-- r2dbc -->
```xml
<dependency>
<groupId>org.mariadb</groupId>
<artifactId>r2dbc-mariadb</artifactId>
<version>1.1.3</version>
<groupId>io.github.cooperlyt</groupId>
<artifactId>uid-reactive-generator-db-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>

```
* Mybatis JDBC:
```xml
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.3.0</version>
</dependency>
```
* Mybatis R2DBC
Refer [reactive-mybatis-support](https://github.com/chenggangpro/reactive-mybatis-support)
* JPA JDBC:
```xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
```
* JPA R2DBC
```xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
</dependency>
```


### Databases(optional)
Table WORKER_NODE scrip:
* Databases scrip:
```sql
DROP TABLE IF EXISTS WORKER_NODE;
CREATE TABLE WORKER_NODE
(
ID BIGINT NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
HOST_NAME VARCHAR(64) NOT NULL COMMENT 'host name',
PORT VARCHAR(64) NOT NULL COMMENT 'port',
TYPE INT NOT NULL COMMENT 'node type: CONTAINER(1), ACTUAL(2), FAKE(3)',
LAUNCH_DATE DATE NOT NULL COMMENT 'launch date',
MODIFIED TIMESTAMP NOT NULL COMMENT 'modified time',
CREATED TIMESTAMP NOT NULL COMMENT 'created time',
PRIMARY KEY(ID)
ID BIGINT NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
HOST VARCHAR(64) NOT NULL COMMENT 'host name',
PORT VARCHAR(64) NOT NULL COMMENT 'port',
TYPE INT NOT NULL COMMENT 'node type: CONTAINER(1), ACTUAL(2), FAKE(3)',
LAUNCH DATE NOT NULL COMMENT 'launch date',
MODIFIED TIMESTAMP NOT NULL COMMENT 'modified time',
CREATED TIMESTAMP NOT NULL COMMENT 'created time',
PRIMARY KEY(ID)
) COMMENT='DB WorkerID Assigner for UID Generator',ENGINE = INNODB;
```

### spring boot configure

Example for mariadb

#### mybatis jdbc

```yml
mybatis:
configuration:
default-fetch-size: 100
default-statement-timeout: 30
map-underscore-to-camel-case: true
spring:
datasource:
driver-class-name: org.mariadb.jdbc.Driver
url: jdbc:mariadb://127.0.0.1:3306/database?
username: root
password: ****
```
#### mybatis r2dbc
refer [reactive-mybatis-support](https://github.com/chenggangpro/reactive-mybatis-support)
```yml

r2dbc:
mybatis:
mapper-locations: classpath:mapper/*.xml
map-underscore-to-camel-case: true
spring:
r2dbc:
mybatis:
r2dbc-url: r2dbc:mariadb://127.0.0.1:3306/database
username: root
password: ****
pool:
max-idle-time: PT3M
validation-query: SELECT 1 FROM DUAL
initial-size: 1
max-size: 3
acquire-retry: 3
validation-depth: REMOTE
max-create-connection-time: PT30S
```
#### jpa jdbc
```yml
spring:
jpa:
show-sql: true
datasource:
driver-class-name: org.mariadb.jdbc.Driver
url: jdbc:mariadb://127.0.0.1:3306/corp?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&allowMultiQueries=true
username: root
password: ****
```
#### jpa r2dbc

```yml

spring:
r2dbc:
url: r2dbc:mariadb://127.0.0.1:3306/corp?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false
username: root
password: ****
# pool:
# initial-size: 11

```


#### CachedUidGenerator rejected handler(optional)
Expand Down
Loading

0 comments on commit 3fdcf76

Please sign in to comment.