Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
Signed-off-by: Jiangnan Jia <[email protected]>
  • Loading branch information
jnan806 committed Oct 27, 2022
1 parent e42d097 commit 0d384e5
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ See the [中文文档](https://opensergo.io/zh-cn/) for document in Chinese.

1. Add dependency in Maven `pom.xml`:

```xml
``` xml
<!-- replace here with the latest version -->
<dependency>
<groupId>io.opensergo</groupId>
Expand All @@ -29,20 +29,28 @@ See the [中文文档](https://opensergo.io/zh-cn/) for document in Chinese.

2. Subscribe data from OpenSergo control plane:

```java
``` java
// 1. Create client with remote host and port of OpenSergo control plane
OpenSergoClient client = new OpenSergoClient(host, port);
// 2. Start the OpenSergo client.
client.start();

// 3. Subscribe the config of the target (namespace, appName, kind)
client.subscribeConfig(new SubscribeKey("default", "my-service", configKind),
new OpenSergoConfigSubscriber() {
// 3. Prepare for subscribing the config of the target (namespace, appName, kind)
// 3.1 Create the SubscribeKey of your target
SubscribeKey subscribeKey = new SubscribeKey("default", "my-service", configKind);
// 3.2 Create the SubscribeInfo of your target by subscribeKey
OpensergoClientSubscribeInfo subscribeInfo = new OpensergoClientSubscribeInfo(subscribeKey);
// 3.3 Add a Subscriber for you target which would listen changes of target
subscribeInfo.addSubscriber(new OpenSergoConfigSubscriber() {
@Override
public boolean onConfigUpdate(SubscribeKey subscribeKey, Object dataList) {
// Handle received config here
// TODO Handle received config here
System.out.println("key: " + subscribeKey + ", data: " + dataList);
return true;
}
});

// 4. Register into OpenSergoClient the SubscribeInfo which was builded above.
// And then the client will subscribe config automatic.
client.registerSubscribeInfo(subscribeInfo);
```

0 comments on commit 0d384e5

Please sign in to comment.