@@ -18,7 +18,7 @@ See the [中文文档](https://opensergo.io/zh-cn/) for document in Chinese.
18
18
19
19
1 . Add dependency in Maven ` pom.xml ` :
20
20
21
- ``` xml
21
+ ``` xml
22
22
<!-- replace here with the latest version -->
23
23
<dependency >
24
24
<groupId >io.opensergo</groupId >
@@ -29,20 +29,28 @@ See the [中文文档](https://opensergo.io/zh-cn/) for document in Chinese.
29
29
30
30
2 . Subscribe data from OpenSergo control plane:
31
31
32
- ``` java
32
+ ``` java
33
33
// 1. Create client with remote host and port of OpenSergo control plane
34
34
OpenSergoClient client = new OpenSergoClient (host, port);
35
35
// 2. Start the OpenSergo client.
36
36
client. start();
37
37
38
- // 3. Subscribe the config of the target (namespace, appName, kind)
39
- client. subscribeConfig(new SubscribeKey (" default" , " my-service" , configKind),
40
- new OpenSergoConfigSubscriber () {
38
+ // 3. Prepare for subscribing the config of the target (namespace, appName, kind)
39
+ // 3.1 Create the SubscribeKey of your target
40
+ SubscribeKey subscribeKey = new SubscribeKey (" default" , " my-service" , configKind);
41
+ // 3.2 Create the SubscribeInfo of your target by subscribeKey
42
+ OpensergoClientSubscribeInfo subscribeInfo = new OpensergoClientSubscribeInfo (subscribeKey);
43
+ // 3.3 Add a Subscriber for you target which would listen changes of target
44
+ subscribeInfo. addSubscriber(new OpenSergoConfigSubscriber () {
41
45
@Override
42
46
public boolean onConfigUpdate (SubscribeKey subscribeKey , Object dataList ) {
43
- // Handle received config here
47
+ // TODO Handle received config here
44
48
System . out. println(" key: " + subscribeKey + " , data: " + dataList);
45
49
return true ;
46
50
}
47
51
});
52
+
53
+ // 4. Register into OpenSergoClient the SubscribeInfo which was builded above.
54
+ // And then the client will subscribe config automatic.
55
+ client. registerSubscribeInfo(subscribeInfo);
48
56
```
0 commit comments