Skip to content

Commit

Permalink
Merge pull request #15 from Ahoo-Wang/reactor
Browse files Browse the repository at this point in the history
Enhancement: Support Reactor programming model
  • Loading branch information
Ahoo-Wang authored Aug 25, 2021
2 parents c6916f5 + 5e3b51e commit 685ffec
Show file tree
Hide file tree
Showing 109 changed files with 1,743 additions and 2,344 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ between process cache and Redis.
> Kotlin DSL
``` kotlin
val coskyVersion = "1.2.10";
val coskyVersion = "1.3.1";
implementation("me.ahoo.cosky:spring-cloud-starter-cosky-config:${coskyVersion}")
implementation("me.ahoo.cosky:spring-cloud-starter-cosky-discovery:${coskyVersion}")
implementation("org.springframework.cloud:spring-cloud-starter-loadbalancer:3.0.3")
Expand All @@ -50,7 +50,7 @@ between process cache and Redis.
<modelVersion>4.0.0</modelVersion>
<artifactId>demo</artifactId>
<properties>
<cosky.version>1.2.10</cosky.version>
<cosky.version>1.3.1</cosky.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -99,21 +99,21 @@ logging:
#### Option 1:Download the executable file
> Download [cosky-rest-api-server](https://github.com/Ahoo-Wang/cosky/releases/download/1.2.10/cosky-rest-api-1.2.10.tar)
> Download [cosky-rest-api-server](https://github.com/Ahoo-Wang/cosky/releases/download/1.3.1/cosky-rest-api-1.3.1.tar)
> tar *cosky-rest-api-1.2.10.tar*
> tar *cosky-rest-api-1.3.1.tar*
```shell
cd cosky-rest-api-1.2.10
# Working directory: cosky-rest-api-1.2.10
cd cosky-rest-api-1.3.1
# Working directory: cosky-rest-api-1.3.1
bin/cosky-rest-api --server.port=8080 --cosky.redis.uri=redis://localhost:6379
```

#### Option 2:Run On Docker

```shell
docker pull ahoowang/cosky-rest-api:1.2.10
docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.2.10
docker pull ahoowang/cosky-rest-api:1.3.1
docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.3.1
```

#### Option 3:Run On Kubernetes
Expand Down Expand Up @@ -141,7 +141,7 @@ spec:
value: standalone
- name: COSKY_REDIS_URI
value: redis://redis-uri:6379
image: ahoowang/cosky-rest-api:1.2.10
image: ahoowang/cosky-rest-api:1.3.1
name: cosky-rest-api
ports:
- containerPort: 8080
Expand Down Expand Up @@ -310,7 +310,7 @@ spec:
``` shell
gradle cosky-config:jmh
# or
java -jar cosky-config/build/libs/cosky-config-1.2.10-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
java -jar cosky-config/build/libs/cosky-config-1.3.1-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
```

```
Expand All @@ -325,7 +325,7 @@ RedisConfigServiceBenchmark.setConfig thrpt 140461.112
``` shell
gradle cosky-discovery:jmh
# or
java -jar cosky-discovery/build/libs/cosky-discovery-1.2.10-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
java -jar cosky-discovery/build/libs/cosky-discovery-1.3.1-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
```

```
Expand Down
22 changes: 11 additions & 11 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
> Kotlin DSL
``` kotlin
val coskyVersion = "1.2.10";
val coskyVersion = "1.3.1";
implementation("me.ahoo.cosky:spring-cloud-starter-cosky-config:${coskyVersion}")
implementation("me.ahoo.cosky:spring-cloud-starter-cosky-discovery:${coskyVersion}")
implementation("org.springframework.cloud:spring-cloud-starter-loadbalancer:3.0.3")
Expand All @@ -49,7 +49,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>demo</artifactId>
<properties>
<cosky.version>1.2.10</cosky.version>
<cosky.version>1.3.1</cosky.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -98,21 +98,21 @@ logging:
#### 方式一:下载可执行文件
> 下载 [rest-api-server](https://github.com/Ahoo-Wang/cosky/releases/download/1.2.10/cosky-rest-api-1.2.10.tar)
> 下载 [rest-api-server](https://github.com/Ahoo-Wang/cosky/releases/download/1.3.1/cosky-rest-api-1.3.1.tar)
> 解压 *cosky-rest-api-1.2.10.tar*
> 解压 *cosky-rest-api-1.3.1.tar*
```shell
cd cosky-rest-api-1.2.10
# 工作目录: cosky-rest-api-1.2.10
cd cosky-rest-api-1.3.1
# 工作目录: cosky-rest-api-1.3.1
bin/cosky-rest-api --server.port=8080 --cosky.redis.uri=redis://localhost:6379
```

#### 方式二:在 Docker 中运行

```shell
docker pull ahoowang/cosky-rest-api:1.2.10
docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.2.10
docker pull ahoowang/cosky-rest-api:1.3.1
docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.3.1
```

#### 方式三:在 Kubernetes 中运行
Expand Down Expand Up @@ -140,7 +140,7 @@ spec:
value: standalone
- name: COSKY_REDIS_URI
value: redis://redis-uri:6379
image: ahoowang/cosky-rest-api:1.2.10
image: ahoowang/cosky-rest-api:1.3.1
name: cosky-rest-api
ports:
- containerPort: 8080
Expand Down Expand Up @@ -310,7 +310,7 @@ spec:
``` shell
gradle cosky-config:jmh
# or
java -jar cosky-config/build/libs/cosky-config-1.2.10-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
java -jar cosky-config/build/libs/cosky-config-1.3.1-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
```

```
Expand All @@ -325,7 +325,7 @@ RedisConfigServiceBenchmark.setConfig thrpt 140461.112
``` shell
gradle cosky-discovery:jmh
# or
java -jar cosky-discovery/build/libs/cosky-discovery-1.2.10-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
java -jar cosky-discovery/build/libs/cosky-discovery-1.3.1-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
```

```
Expand Down
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ val libraryProjects = publishProjects - bomProjects

ext {
set("lombokVersion", "1.18.20")
set("springBootVersion", "2.4.7")
set("springBootVersion", "2.4.10")
set("springCloudVersion", "2020.0.3")
set("jmhVersion", "1.29")
set("guavaVersion", "30.0-jre")
set("commonsIOVersion", "2.10.0")
set("springfoxVersion", "3.0.0")
set("metricsVersion", "4.2.0")
set("jjwtVersion", "0.11.2")
set("cosIdVersion", "1.3.6")
set("cosIdVersion", "1.3.13")
set("libraryProjects", libraryProjects)
}

Expand Down Expand Up @@ -95,6 +95,7 @@ configure(libraryProjects) {
this.add("testImplementation", "ch.qos.logback:logback-classic")
this.add("testImplementation", "org.junit.jupiter:junit-jupiter-api")
this.add("testRuntimeOnly", "org.junit.jupiter:junit-jupiter-engine")
this.add("testImplementation", "io.projectreactor:reactor-test")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import io.lettuce.core.api.StatefulRedisConnection;
import me.ahoo.cosky.config.redis.ConsistencyRedisConfigService;
import me.ahoo.cosky.config.redis.RedisConfigService;
import me.ahoo.cosky.core.listener.DefaultMessageListenable;
import me.ahoo.cosky.core.listener.MessageListenable;
import me.ahoo.cosky.core.listener.RedisMessageListenable;
import org.openjdk.jmh.annotations.*;

import java.util.Objects;
Expand Down Expand Up @@ -52,9 +52,9 @@ public void setup() {
redisClient = RedisClient.create("redis://localhost:6379");
redisConnection = redisClient.connect();

RedisConfigService redisConfigService = new RedisConfigService(redisConnection.async());
RedisConfigService redisConfigService = new RedisConfigService(redisConnection.reactive());
redisConfigService.setConfig(configId, configData);
messageListenable = new RedisMessageListenable(redisClient.connectPubSub());
messageListenable = new DefaultMessageListenable(redisClient.connectPubSub().reactive());
configService = new ConsistencyRedisConfigService(redisConfigService, messageListenable);
}

Expand All @@ -67,17 +67,10 @@ public void tearDown() {
if (Objects.nonNull(redisClient)) {
redisClient.shutdown();
}
if (Objects.nonNull(messageListenable)) {
try {
messageListenable.close();
} catch (Exception exception) {
throw new RuntimeException(exception);
}
}
}

@Benchmark
public Config getConfig() {
return configService.getConfig(namespace, configId).join();
return configService.getConfig(namespace, configId).block();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void setup() {
System.out.println("\n ----- RedisConfigBenchmark setup ----- \n");
redisClient = RedisClient.create("redis://localhost:6379");
redisConnection = redisClient.connect();
configService = new RedisConfigService(redisConnection.async());
configService = new RedisConfigService(redisConnection.reactive());
configService.setConfig(namespace, configId, configData);
atomicInteger = new AtomicInteger();
}
Expand All @@ -68,12 +68,12 @@ public void tearDown() {
@Benchmark
public Boolean setConfig() {
String randomConfigId = String.valueOf(atomicInteger.incrementAndGet());
return configService.setConfig(namespace, randomConfigId, configData).join();
return configService.setConfig(namespace, randomConfigId, configData).block();
}

@Benchmark
public Config getConfig() {
return configService.getConfig(namespace, configId).join();
return configService.getConfig(namespace, configId).block();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

package me.ahoo.cosky.config;

import java.util.concurrent.CompletableFuture;
import reactor.core.publisher.Mono;

/**
* @author ahoo wang
*/
public interface ConfigListenable {

CompletableFuture<Boolean> addListener(NamespacedConfigId namespacedConfigId, ConfigChangedListener configChangedListener);
void addListener(NamespacedConfigId namespacedConfigId, ConfigChangedListener configChangedListener);

CompletableFuture<Boolean> removeListener(NamespacedConfigId namespacedConfigId, ConfigChangedListener configChangedListener);
void removeListener(NamespacedConfigId namespacedConfigId, ConfigChangedListener configChangedListener);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,32 @@

package me.ahoo.cosky.config;

import me.ahoo.cosky.core.NamespacedContext;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
* @author ahoo wang
*/
public interface ConfigRollback {
int HISTORY_SIZE = 10;

CompletableFuture<Boolean> rollback(String configId, int targetVersion);
default Mono<Boolean> rollback(String configId, int targetVersion) {
return rollback(NamespacedContext.GLOBAL.getRequiredNamespace(), configId, targetVersion);
}

CompletableFuture<Boolean> rollback(String namespace, String configId, int targetVersion);
Mono<Boolean> rollback(String namespace, String configId, int targetVersion);

CompletableFuture<List<ConfigVersion>> getConfigVersions(String configId);
default Mono<List<ConfigVersion>> getConfigVersions(String configId) {
return getConfigVersions(NamespacedContext.GLOBAL.getRequiredNamespace(), configId);
}

CompletableFuture<List<ConfigVersion>> getConfigVersions(String namespace, String configId);
Mono<List<ConfigVersion>> getConfigVersions(String namespace, String configId);

CompletableFuture<ConfigHistory> getConfigHistory(String configId, int version);
default Mono<ConfigHistory> getConfigHistory(String configId, int version) {
return getConfigHistory(NamespacedContext.GLOBAL.getRequiredNamespace(), configId, version);
}

CompletableFuture<ConfigHistory> getConfigHistory(String namespace, String configId, int version);
Mono<ConfigHistory> getConfigHistory(String namespace, String configId, int version);
}
30 changes: 20 additions & 10 deletions cosky-config/src/main/java/me/ahoo/cosky/config/ConfigService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,40 @@

package me.ahoo.cosky.config;

import me.ahoo.cosky.core.NamespacedContext;
import reactor.core.publisher.Mono;

import java.util.Set;
import java.util.concurrent.CompletableFuture;

/**
* @author ahoo wang
*/
public interface ConfigService extends ConfigRollback {

CompletableFuture<Set<String>> getConfigs();
default Mono<Set<String>> getConfigs() {
return getConfigs(NamespacedContext.GLOBAL.getRequiredNamespace());
}

CompletableFuture<Set<String>> getConfigs(String namespace);
Mono<Set<String>> getConfigs(String namespace);

CompletableFuture<Config> getConfig(String configId);
default Mono<Config> getConfig(String configId) {
return getConfig(NamespacedContext.GLOBAL.getRequiredNamespace(), configId);
}

CompletableFuture<Config> getConfig(String namespace, String configId);
Mono<Config> getConfig(String namespace, String configId);

CompletableFuture<Boolean> setConfig(String configId, String data);
default Mono<Boolean> setConfig(String configId, String data) {
return setConfig(NamespacedContext.GLOBAL.getRequiredNamespace(), configId, data);
}

CompletableFuture<Boolean> setConfig(String namespace, String configId, String data);
Mono<Boolean> setConfig(String namespace, String configId, String data);

CompletableFuture<Boolean> removeConfig(String configId);
default Mono<Boolean> removeConfig(String configId) {
return removeConfig(NamespacedContext.GLOBAL.getRequiredNamespace(), configId);
}

CompletableFuture<Boolean> removeConfig(String namespace, String configId);
Mono<Boolean> removeConfig(String namespace, String configId);


CompletableFuture<Boolean> containsConfig(String namespace, String configId);
Mono<Boolean> containsConfig(String namespace, String configId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@

package me.ahoo.cosky.config.redis;

import io.lettuce.core.RedisFuture;
import io.lettuce.core.api.async.RedisScriptingAsyncCommands;
import io.lettuce.core.api.reactive.RedisScriptingReactiveCommands;
import me.ahoo.cosky.core.redis.RedisScripts;
import reactor.core.publisher.Mono;

import java.util.concurrent.CompletableFuture;
import java.util.function.Function;

/**
Expand All @@ -28,13 +27,13 @@ public final class ConfigRedisScripts {
public static final String CONFIG_REMOVE = "config_remove.lua";
public static final String CONFIG_ROLLBACK = "config_rollback.lua";

public static <T> CompletableFuture<T> doConfigSet(RedisScriptingAsyncCommands<String, String> scriptingCommands, Function<String, RedisFuture<T>> doSha) {
public static <T> Mono<T> doConfigSet(RedisScriptingReactiveCommands<String, String> scriptingCommands, Function<String, Mono<T>> doSha) {
return RedisScripts.doEnsureScript(CONFIG_SET, scriptingCommands, doSha);
}
public static <T> CompletableFuture<T> doConfigRemove(RedisScriptingAsyncCommands<String, String> scriptingCommands, Function<String, RedisFuture<T>> doSha) {
public static <T> Mono<T> doConfigRemove(RedisScriptingReactiveCommands<String, String> scriptingCommands, Function<String, Mono<T>> doSha) {
return RedisScripts.doEnsureScript(CONFIG_REMOVE, scriptingCommands, doSha);
}
public static <T> CompletableFuture<T> doConfigRollback(RedisScriptingAsyncCommands<String, String> scriptingCommands, Function<String, RedisFuture<T>> doSha) {
public static <T> Mono<T> doConfigRollback(RedisScriptingReactiveCommands<String, String> scriptingCommands, Function<String, Mono<T>> doSha) {
return RedisScripts.doEnsureScript(CONFIG_ROLLBACK, scriptingCommands, doSha);
}

Expand Down
Loading

0 comments on commit 685ffec

Please sign in to comment.