Apollo-Server Http interface documentation
https://ctripcorp.github.io/apollo/#/zh/usage/other-language-client-user-guide
ConfigFileController Http interface with cache to read configuration from Apollo
The interface will get the configuration from the cache, which is suitable for high-frequency configuration pull requests, such as a simple polling configuration every 30 seconds
// 使用 Guava 对配置信息进行缓存
private Cache<String, String> localCache;
localCache = CacheBuilder.newBuilder()
.expireAfterWrite(EXPIRE_AFTER_WRITE, TimeUnit.MINUTES)
.weigher((Weigher<String, String>) (key, value) -> value == null ? 0 : value.length())
.maximumWeight(MAX_CACHE_SIZE)
.removalListener(notification -> {
String cacheKey = notification.getKey();
logger.debug("removing cache key: {}", cacheKey);
if (!cacheKey2WatchedKeys.containsKey(cacheKey)) {
return;
}
//create a new list to avoid ConcurrentModificationException
List<String> watchedKeys = new ArrayList<>(cacheKey2WatchedKeys.get(cacheKey));
for (String watchedKey : watchedKeys) {
watchedKeys2CacheKey.remove(watchedKey, cacheKey);
}
cacheKey2WatchedKeys.removeAll(cacheKey);
logger.debug("removed cache key: {}", cacheKey);
})
.build();
// outputFormat 默认 properties
String cacheKey = assembleCacheKey(outputFormat, appId, clusterName, namespace, dataCenter);
String result = localCache.getIfPresent(cacheKey);
- The ip={clientIp} parameter is optional, used to achieve grayscale publishing
com.ctrip.framework.apollo.configservice.controller.ConfigFileController
URL: {
config_server_url}/configfiles/json/{
appId}/{
clusterName}/{
namespaceName}?ip={
clientIp}
Method: GET
// Http Response 返回结果
{
"portal.elastic.document.type":"biz",
"portal.elastic.cluster.name":"hermes-es-fws"
}
ConfigController Http interface without cache reads configuration from Apollo
The interface will get the configuration directly from the database, which can be used with configuration push notifications to update the configuration in real time
-
releaseKey={releaseKey}: Just pass in the releaseKey in the last returned object, which is used to compare the versions to the server. If the version does not change, the server will directly return 304 to save traffic and calculations.
-
The ip={clientIp} parameter is optional, used to achieve grayscale publishing
com.ctrip.framework.apollo.configservice.controller.ConfigController
URL: {
config_server_url}/configs/{
appId}/{
clusterName}/{
namespaceName}?releaseKey={
releaseKey}&ip={
clientIp}
Method: GET
// Http Response 返回结果
{
"appId": "100004458",
"cluster": "default",
"namespaceName": "application",
"configurations": {
"portal.elastic.document.type":"biz",
"portal.elastic.cluster.name":"hermes-es-fws"
},
"releaseKey": "20170430092936-dee2d58e74515ff3"
}
NotificationControllerV2 application aware configuration update
Apollo provides push notifications for configuration updates based on Http long polling. Third-party clients can decide whether they need to use this function according to their actual needs.
com.ctrip.framework.apollo.configservice.controller.NotificationControllerV2
URL: {
config_server_url}/notifications/v2?appId={
appId}&cluster={
clusterName}¬ifications={
notifications}
Method: GET
// Http Response 返回结果
[
{
"namespaceName": "application",
"notificationId": 101
}
]
// 如果返回的HttpStatus是304,说明配置没有变化
// 如果返回的HttpStauts是200,说明配置有变化,针对变化的namespace重新去服务端拉取配置