Skip to content

Commit f6f1471

Browse files
committed
implement apollo dynamic config
Signed-off-by: chenzhenyang <[email protected]>
1 parent 28d6c76 commit f6f1471

File tree

17 files changed

+1259
-1
lines changed

17 files changed

+1259
-1
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
<nexus.staging.plugin.version>1.6.7</nexus.staging.plugin.version>
8686
<central.publishing.maven.plugin.version>0.5.0</central.publishing.maven.plugin.version>
8787
<frontend.plugin.version>1.12.1</frontend.plugin.version>
88+
<apollo.version>2.4.0</apollo.version>
8889

8990
<sermant.name>sermant-agent</sermant.name>
9091
<sermant.basedir>${pom.basedir}</sermant.basedir>

sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/dynamicconfig/common/DynamicConfigServiceType.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
* @since 2021-12-27
2424
*/
2525
public enum DynamicConfigServiceType {
26+
27+
/**
28+
* apollo configuration center
29+
*/
30+
APOLLO,
2631
/**
2732
* zookeeper configuration center
2833
*/

sermant-agentcore/sermant-agentcore-implement/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@
126126
<artifactId>zookeeper</artifactId>
127127
<version>${zookeeper.version}</version>
128128
</dependency>
129+
<dependency>
130+
<groupId>com.ctrip.framework.apollo</groupId>
131+
<artifactId>apollo-client</artifactId>
132+
<version>${apollo.version}</version>
133+
</dependency>
134+
<dependency>
135+
<groupId>com.ctrip.framework.apollo</groupId>
136+
<artifactId>apollo-openapi</artifactId>
137+
<version>${apollo.version}</version>
138+
</dependency>
139+
<dependency>
140+
<groupId>com.ctrip.framework.apollo</groupId>
141+
<artifactId>apollo-core</artifactId>
142+
<version>${apollo.version}</version>
143+
</dependency>
129144
<dependency>
130145
<groupId>com.alibaba.nacos</groupId>
131146
<artifactId>nacos-client</artifactId>

sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/service/dynamicconfig/BufferedDynamicConfigService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import io.sermant.core.service.dynamicconfig.DynamicConfigService;
2020
import io.sermant.core.service.dynamicconfig.common.DynamicConfigListener;
21+
import io.sermant.implement.service.dynamicconfig.apollo.ApolloDynamicConfigService;
2122
import io.sermant.implement.service.dynamicconfig.kie.KieDynamicConfigService;
2223
import io.sermant.implement.service.dynamicconfig.nacos.NacosDynamicConfigService;
2324
import io.sermant.implement.service.dynamicconfig.zookeeper.ZooKeeperDynamicConfigService;
@@ -50,6 +51,9 @@ public BufferedDynamicConfigService() {
5051
case NACOS:
5152
service = new NacosDynamicConfigService();
5253
break;
54+
case APOLLO:
55+
service = new ApolloDynamicConfigService();
56+
break;
5357
default:
5458
service = new ZooKeeperDynamicConfigService();
5559
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (C) 2025-2025 Sermant Authors. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.sermant.implement.service.dynamicconfig.apollo;
18+
19+
import com.ctrip.framework.apollo.ConfigChangeListener;
20+
21+
import java.io.Closeable;
22+
import java.util.List;
23+
import java.util.Map;
24+
import java.util.logging.Level;
25+
import java.util.logging.Logger;
26+
27+
/**
28+
* @author Chen Zhenyang
29+
* @since 2025/8/7
30+
*/
31+
public class ApolloBufferedClient implements Closeable {
32+
private static final Logger LOGGER = Logger.getLogger(ApolloBufferedClient.class.getName());
33+
private final ApolloClient apolloClient;
34+
35+
public ApolloBufferedClient() {
36+
apolloClient = new ApolloClient();
37+
}
38+
39+
@Override
40+
public void close() {
41+
try {
42+
apolloClient.close();
43+
} catch (Exception e) {
44+
LOGGER.log(Level.SEVERE, "Apollo close exception, msg is: ", e);
45+
}
46+
}
47+
48+
public boolean publishConfig(String key, String group, String content) {
49+
return apolloClient.publishConfig(key, group, content);
50+
}
51+
52+
public boolean removeConfig(String key, String group) {
53+
return apolloClient.removeConfig(key, group);
54+
}
55+
56+
public List<String> getListKeysFromGroup(String group) {
57+
Map<String, List<String>> res = apolloClient.getConfigList(null, group, true);
58+
return res.get(group);
59+
}
60+
61+
public String getConfig(String key, String group) {
62+
return apolloClient.getConfig(key, group);
63+
}
64+
65+
public boolean addGroupListener(String group, ConfigChangeListener apolloListener) {
66+
return apolloClient.addGroupListener(group, apolloListener);
67+
}
68+
69+
public boolean addConfigListener(String key, String group, ConfigChangeListener apolloListener) {
70+
return apolloClient.addConfigListener(key, group, apolloListener);
71+
}
72+
73+
public boolean removeConfigListener(String validGroup, ConfigChangeListener ccl) {
74+
return apolloClient.removeConfigListener(validGroup, ccl);
75+
}
76+
}

0 commit comments

Comments
 (0)