Skip to content

Commit

Permalink
- add: cosky-mirror
Browse files Browse the repository at this point in the history
- enhance: ServiceChangedListener
  • Loading branch information
Ahoo-Wang committed Jun 1, 2021
1 parent f342a42 commit 9570d47
Show file tree
Hide file tree
Showing 34 changed files with 656 additions and 129 deletions.
38 changes: 22 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@ between process cache and Redis.

![CoSky-Configuration](./docs/CoSky-Configuration.png)

### CoSky-Mirror

> CoSky-Mirror is like a mirror placed between Nacos and CoSky to build a unified service discovery platform.
![CoSky-Mirror](./docs/CoSky-Mirror.png)

## Installation

### Gradle

> Kotlin DSL
``` kotlin
val coskyVersion = "1.0.1";
val coskyVersion = "1.1.0";
implementation("me.ahoo.cosky:spring-cloud-starter-cosky-config:${coskyVersion}")
implementation("me.ahoo.cosky:spring-cloud-starter-cosky-discovery:${coskyVersion}")
```
Expand All @@ -43,7 +49,7 @@ between process cache and Redis.
<modelVersion>4.0.0</modelVersion>
<artifactId>demo</artifactId>
<properties>
<cosky.version>1.0.1</cosky.version>
<cosky.version>1.1.0</cosky.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -87,30 +93,30 @@ logging:
#### Option 1:Download the executable file
> Download [cosky-rest-api-server](https://github.com/Ahoo-Wang/cosky/releases/download/1.0.1/cosky-rest-api-1.0.1.tar)
> Download [cosky-rest-api-server](https://github.com/Ahoo-Wang/cosky/releases/download/1.1.0/cosky-rest-api-1.1.0.tar)
> tar *cosky-rest-api-1.0.1.tar*
> tar *cosky-rest-api-1.1.0.tar*
```shell
cd cosky-rest-api-1.0.1
# Working directory: cosky-rest-api-1.0.1
cd cosky-rest-api-1.1.0
# Working directory: cosky-rest-api-1.1.0
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.0.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.0.1
docker pull ahoowang/cosky-rest-api:1.1.0
docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.1.0
```

##### MacBook Pro (M1)

> Please use *ahoowang/cosky-rest-api:1.0.1-armv7*
> Please use *ahoowang/cosky-rest-api:1.1.0-armv7*
```shell
docker pull ahoowang/cosky-rest-api:1.0.1-armv7
docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.0.1-armv7
docker pull ahoowang/cosky-rest-api:1.1.0-armv7
docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.1.0-armv7
```

#### Option 3:Run On Kubernetes
Expand All @@ -136,7 +142,7 @@ spec:
value: standalone
- name: COSKY_REDIS_URI
value: redis://redis-uri:6379
image: ahoowang/cosky-rest-api:1.0.1
image: ahoowang/cosky-rest-api:1.1.0
name: cosky-rest-api
resources:
limits:
Expand Down Expand Up @@ -267,12 +273,12 @@ spec:
``` shell
gradle cosky-config:jmh
# or
java -jar cosky-config/build/libs/cosky-config-1.0.1-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
java -jar cosky-config/build/libs/cosky-config-1.1.0-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
```

```
# JMH version: 1.29
# VM version: JDK 11.0.11, OpenJDK 64-Bit Server VM, 11.0.11+9-LTS
# VM version: JDK 11.1.01, OpenJDK 64-Bit Server VM, 11.1.01+9-LTS
# VM invoker: /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/bin/java
# VM options: -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/Users/ahoo/cosky/cosky-config/build/tmp/jmh -Duser.country=CN -Duser.language=zh -Duser.variant
# Blackhole mode: full + dont-inline hint
Expand All @@ -293,12 +299,12 @@ RedisConfigServiceBenchmark.setConfig thrpt 103659.132
``` shell
gradle cosky-discovery:jmh
# or
java -jar cosky-discovery/build/libs/cosky-discovery-1.0.1-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
java -jar cosky-discovery/build/libs/cosky-discovery-1.1.0-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
```

```
# JMH version: 1.29
# VM version: JDK 11.0.11, OpenJDK 64-Bit Server VM, 11.0.11+9-LTS
# VM version: JDK 11.1.01, OpenJDK 64-Bit Server VM, 11.1.01+9-LTS
# VM invoker: /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/bin/java
# VM options: -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/Users/ahoo/cosky/cosky-discovery/build/tmp/jmh -Duser.country=CN -Duser.language=zh -Duser.variant
# Blackhole mode: full + dont-inline hint
Expand Down
38 changes: 22 additions & 16 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@

![CoSky-Configuration](./docs/CoSky-Configuration.png)

### CoSky-Mirror

> CoSky-Mirror 就像一个镜子放在 Nacos、CoSky 中间,构建一个统一的服务发现平台。
![CoSky-Mirror](./docs/CoSky-Mirror.png)

## 安装

### Gradle

> Kotlin DSL
``` kotlin
val coskyVersion = "1.0.1";
val coskyVersion = "1.1.0";
implementation("me.ahoo.cosky:spring-cloud-starter-cosky-config:${coskyVersion}")
implementation("me.ahoo.cosky:spring-cloud-starter-cosky-discovery:${coskyVersion}")
```
Expand All @@ -38,7 +44,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>demo</artifactId>
<properties>
<cosky.version>1.0.1</cosky.version>
<cosky.version>1.1.0</cosky.version>
</properties>

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

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

```shell
docker pull ahoowang/cosky-rest-api:1.0.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.0.1
docker pull ahoowang/cosky-rest-api:1.1.0
docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.1.0
```

##### MacBook Pro (M1)

> 请使用 *ahoowang/cosky-rest-api:1.0.1-armv7*
> 请使用 *ahoowang/cosky-rest-api:1.1.0-armv7*
```shell
docker pull ahoowang/cosky-rest-api:1.0.1-armv7
docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.0.1-armv7
docker pull ahoowang/cosky-rest-api:1.1.0-armv7
docker run --name cosky-rest-api -d -p 8080:8080 --link redis -e COSKY_REDIS_URI=redis://redis:6379 ahoowang/cosky-rest-api:1.1.0-armv7
```

#### 方式三:在 Kubernetes 中运行
Expand All @@ -131,7 +137,7 @@ spec:
value: standalone
- name: COSKY_REDIS_URI
value: redis://redis-uri:6379
image: ahoowang/cosky-rest-api:1.0.1
image: ahoowang/cosky-rest-api:1.1.0
name: cosky-rest-api
resources:
limits:
Expand Down Expand Up @@ -262,12 +268,12 @@ spec:
``` shell
gradle cosky-config:jmh
# or
java -jar cosky-config/build/libs/cosky-config-1.0.1-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
java -jar cosky-config/build/libs/cosky-config-1.1.0-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
```

```
# JMH version: 1.29
# VM version: JDK 11.0.11, OpenJDK 64-Bit Server VM, 11.0.11+9-LTS
# VM version: JDK 11.1.01, OpenJDK 64-Bit Server VM, 11.1.01+9-LTS
# VM invoker: /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/bin/java
# VM options: -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/Users/ahoo/cosky/config/build/tmp/jmh -Duser.country=CN -Duser.language=zh -Duser.variant
# Blackhole mode: full + dont-inline hint
Expand All @@ -288,12 +294,12 @@ RedisConfigServiceBenchmark.setConfig thrpt 103659.132
``` shell
gradle cosky-discovery:jmh
# or
java -jar cosky-discovery/build/libs/cosky-discovery-1.0.1-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
java -jar cosky-discovery/build/libs/cosky-discovery-1.1.0-jmh.jar -bm thrpt -t 25 -wi 1 -rf json -f 1
```

```
# JMH version: 1.29
# VM version: JDK 11.0.11, OpenJDK 64-Bit Server VM, 11.0.11+9-LTS
# VM version: JDK 11.1.01, OpenJDK 64-Bit Server VM, 11.1.01+9-LTS
# VM invoker: /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/bin/java
# VM options: -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/Users/ahoo/cosky/discovery/build/tmp/jmh -Duser.country=CN -Duser.language=zh -Duser.variant
# Blackhole mode: full + dont-inline hint
Expand Down
5 changes: 4 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ val coreProjects = listOf(
project(":cosky-discovery")
)
val restApiProject = project(":cosky-rest-api")
val publishProjects = subprojects - restApiProject
val mirrorProject = project(":cosky-mirror")
val serverProjects = listOf(restApiProject, mirrorProject)
val publishProjects = subprojects - serverProjects
val libraryProjects = publishProjects - bomProjects

ext {
Expand All @@ -28,6 +30,7 @@ ext {
set("jmhVersion", "1.29")
set("guavaVersion", "30.0-jre")
set("springfoxVersion", "3.0.0")
set("metricsVersion", "4.2.0")
set("libraryProjects", libraryProjects)
}

Expand Down
1 change: 1 addition & 0 deletions cosky-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dependencies {
api("io.lettuce:lettuce-core")

}
1 change: 1 addition & 0 deletions cosky-dependencies/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ dependencies {
api("org.projectlombok:lombok:${rootProject.ext.get("lombokVersion")}")
api("com.google.guava:guava:${rootProject.ext.get("guavaVersion")}")
api("io.springfox:springfox-boot-starter:${rootProject.ext.get("springfoxVersion")}")
api("io.dropwizard.metrics:metrics-core:${rootProject.ext.get("metricsVersion")}")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package me.ahoo.cosky.discovery;

import com.google.common.base.Objects;
import me.ahoo.cosky.core.Namespaced;

/**
* @author ahoo wang
*/
public class NamespacedInstanceId implements Namespaced {
private final String namespace;
private final String instanceId;

public NamespacedInstanceId(String namespace, String instanceId) {
this.namespace = namespace;
this.instanceId = instanceId;
}

public static NamespacedInstanceId of(String namespace, String instanceId) {
return new NamespacedInstanceId(namespace, instanceId);
}

@Override
public String getNamespace() {
return namespace;
}

public String getInstanceId() {
return instanceId;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof NamespacedInstanceId)) return false;
NamespacedInstanceId that = (NamespacedInstanceId) o;
return Objects.equal(namespace, that.namespace) && Objects.equal(instanceId, that.instanceId);
}

@Override
public int hashCode() {
return Objects.hashCode(namespace, instanceId);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.extern.slf4j.Slf4j;
import lombok.var;

import java.util.Set;
import java.util.Map;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

Expand Down Expand Up @@ -63,7 +63,7 @@ public void stop() {
private void renew() {
final int times = renewCounter.incrementAndGet();
final Stopwatch stopwatch = Stopwatch.createStarted();
final Set<NamespacedServiceInstance> instances = serviceRegistry.getRegisteredEphemeralInstances();
final Map<NamespacedInstanceId, ServiceInstance> instances = serviceRegistry.getRegisteredEphemeralInstances();
if (log.isDebugEnabled()) {
log.debug("renew - instances size:{} start - times@[{}] .", instances.size(), times);
}
Expand All @@ -76,10 +76,11 @@ private void renew() {
}

CompletableFuture<Boolean>[] renewFutures = new CompletableFuture[instances.size()];
var instanceIterator = instances.iterator();

var instanceIterator = instances.entrySet().iterator();
for (int i = 0; i < renewFutures.length; i++) {
var namespacedServiceInstance = instanceIterator.next();
renewFutures[i] = serviceRegistry.renew(namespacedServiceInstance.getNamespace(), namespacedServiceInstance.getServiceInstance())
renewFutures[i] = serviceRegistry.renew(namespacedServiceInstance.getKey().getNamespace(), namespacedServiceInstance.getValue())
.exceptionally((ex) -> {
if (log.isWarnEnabled()) {
log.warn("renew - failed.", ex);
Expand Down
Loading

0 comments on commit 9570d47

Please sign in to comment.