From ec94b89762b89458d8f816e7deb465bdc52e7061 Mon Sep 17 00:00:00 2001 From: Terry Lam <36256759+TerryLam2010@users.noreply.github.com> Date: Thu, 12 Dec 2024 23:10:15 +0800 Subject: [PATCH 1/3] add multiple appid dosc add multiple appid dosc --- docs/en/client/java-sdk-user-guide.md | 23 +++++++++++++++++++++++ docs/zh/client/java-sdk-user-guide.md | 26 ++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/docs/en/client/java-sdk-user-guide.md b/docs/en/client/java-sdk-user-guide.md index eb8e11dbb44..cfe93ee4cb4 100644 --- a/docs/en/client/java-sdk-user-guide.md +++ b/docs/en/client/java-sdk-user-guide.md @@ -611,6 +611,17 @@ ConfigFile configFile = ConfigService.getConfigFile("test", ConfigFileFormat.XML String content = configFile.getContent(); ``` +### 3.1.5 Read the configuration corresponding to multiple appid and their namespaces.(added in version 2.4.0) +Specify the corresponding appid and namespace to retrieve the config, and then obtain the properties. +```java +String someAppId = "Animal"; +String somePublicNamespace = "CAT"; +Config config = ConfigService.getConfig(someAppId, somePublicNamespace); +String someKey = "someKeyFromPublicNamespace"; +String someDefaultValue = "someDefaultValueForTheKey"; +String value = config.getProperty(someKey, someDefaultValue); +``` + ## 3.2 Spring integration approach ### 3.2.1 Configuration @@ -749,6 +760,18 @@ public class SomeAppConfig { public class AnotherAppConfig {} ``` +4.Support for multiple appid (added in version 2.4.0) +```java +// Added support for loading multiple appid their corresponding namespaces. +// Note that when using multiple appid, if there are keys that are the same, +// only the key from the prioritized loaded appid will be retrieved +@Configuration +@EnableApolloConfig(value = {"FX.apollo", "application.yml"}, + multipleConfigs = {@MultipleConfig( appid = "ORDER_SERVICE", namespaces = {"ORDER.apollo"})} +) +public class SomeAppConfig {} +``` + #### 3.2.1.3 Spring Boot integration methods (recommended) Spring Boot supports the above two integration methods in addition to configuration via application.properties/bootstrap.properties, which enables configuration to be injected at an earlier stage, such as scenarios that use `@ConditionalOnProperty` or have some spring-boot-starter needs to read the configuration to do something in the startup phase (e.g. [dubbo-spring-boot-project](https://github.com/apache/incubator-dubbo-spring-boot-project)). So for Spring Boot environment it is recommended to access Apollo (requires version 0.10.0 and above) by the following way. diff --git a/docs/zh/client/java-sdk-user-guide.md b/docs/zh/client/java-sdk-user-guide.md index fa12873ad89..7e9e31da49b 100644 --- a/docs/zh/client/java-sdk-user-guide.md +++ b/docs/zh/client/java-sdk-user-guide.md @@ -1,4 +1,4 @@ ->注意:本文档适用对象是Apollo系统的使用者,如果你是公司内Apollo系统的开发者/维护人员,建议先参考[Apollo开发指南](zh/contribution/apollo-development-guide)。 +~~>注意:本文档适用对象是Apollo系统的使用者,如果你是公司内Apollo系统的开发者/维护人员,建议先参考[Apollo开发指南](zh/contribution/apollo-development-guide)。 #   # 一、准备工作 @@ -583,6 +583,17 @@ ConfigFile configFile = ConfigService.getConfigFile("test", ConfigFileFormat.XML String content = configFile.getContent(); ``` +### 3.1.5 读取多AppId对应namespace的配置 +指定对应的AppId和namespace来获取Config,再获取属性 +```java +String someAppId = "Animal"; +String somePublicNamespace = "CAT"; +Config config = ConfigService.getConfig(someAppId, somePublicNamespace); +String someKey = "someKeyFromPublicNamespace"; +String someDefaultValue = "someDefaultValueForTheKey"; +String value = config.getProperty(someKey, someDefaultValue); +``` + ## 3.2 Spring整合方式 ### 3.2.1 配置 @@ -719,6 +730,17 @@ public class SomeAppConfig { public class AnotherAppConfig {} ``` +4.多appId的支持(新增于2.4.0版本) +```java +// 新增支持了多appId和对应namespace的加载,注意使用多appId的情况下,key相同的情况,只会取优先加载appId的那一个key +@Configuration +@EnableApolloConfig(value = {"FX.apollo", "application.yml"}, + multipleConfigs = {@MultipleConfig( appid = "ORDER_SERVICE", namespaces = {"ORDER.apollo"})} +) +public class SomeAppConfig {} +``` + + #### 3.2.1.3 Spring Boot集成方式(推荐) Spring Boot除了支持上述两种集成方式以外,还支持通过application.properties/bootstrap.properties来配置,该方式能使配置在更早的阶段注入,比如使用`@ConditionalOnProperty`的场景或者是有一些spring-boot-starter在启动阶段就需要读取配置做一些事情(如[dubbo-spring-boot-project](https://github.com/apache/incubator-dubbo-spring-boot-project)),所以对于Spring Boot环境建议通过以下方式来接入Apollo(需要0.10.0及以上版本)。 @@ -1311,4 +1333,4 @@ interface是`com.ctrip.framework.apollo.spi.ConfigServiceLoadBalancerClient`。 输入是meta server返回的多个ConfigService,输出是1个ConfigService。 -默认服务提供是`com.ctrip.framework.apollo.spi.RandomConfigServiceLoadBalancerClient`,使用random策略,也就是随机从多个ConfigService中选择1个ConfigService。 +默认服务提供是`com.ctrip.framework.apollo.spi.RandomConfigServiceLoadBalancerClient`,使用random策略,也就是随机从多个ConfigService中选择1个ConfigService。~~ From fedb5adc8626129a1a5f091c2a1d4fe0f6ba1031 Mon Sep 17 00:00:00 2001 From: Terry Lam <36256759+TerryLam2010@users.noreply.github.com> Date: Thu, 12 Dec 2024 23:15:52 +0800 Subject: [PATCH 2/3] fix some problem --- docs/zh/client/java-sdk-user-guide.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/zh/client/java-sdk-user-guide.md b/docs/zh/client/java-sdk-user-guide.md index 7e9e31da49b..87e4f322e4b 100644 --- a/docs/zh/client/java-sdk-user-guide.md +++ b/docs/zh/client/java-sdk-user-guide.md @@ -1,4 +1,4 @@ -~~>注意:本文档适用对象是Apollo系统的使用者,如果你是公司内Apollo系统的开发者/维护人员,建议先参考[Apollo开发指南](zh/contribution/apollo-development-guide)。 +>注意:本文档适用对象是Apollo系统的使用者,如果你是公司内Apollo系统的开发者/维护人员,建议先参考[Apollo开发指南](zh/contribution/apollo-development-guide)。 #   # 一、准备工作 @@ -1333,4 +1333,4 @@ interface是`com.ctrip.framework.apollo.spi.ConfigServiceLoadBalancerClient`。 输入是meta server返回的多个ConfigService,输出是1个ConfigService。 -默认服务提供是`com.ctrip.framework.apollo.spi.RandomConfigServiceLoadBalancerClient`,使用random策略,也就是随机从多个ConfigService中选择1个ConfigService。~~ +默认服务提供是`com.ctrip.framework.apollo.spi.RandomConfigServiceLoadBalancerClient`,使用random策略,也就是随机从多个ConfigService中选择1个ConfigService。 From 45bb064f7a26ecbb079002872672624285dfba2e Mon Sep 17 00:00:00 2001 From: Jason Song Date: Sat, 14 Dec 2024 14:24:54 +0800 Subject: [PATCH 3/3] Apply suggestions from code review --- docs/en/client/java-sdk-user-guide.md | 2 +- docs/zh/client/java-sdk-user-guide.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/client/java-sdk-user-guide.md b/docs/en/client/java-sdk-user-guide.md index cfe93ee4cb4..276d59a27c7 100644 --- a/docs/en/client/java-sdk-user-guide.md +++ b/docs/en/client/java-sdk-user-guide.md @@ -767,7 +767,7 @@ public class AnotherAppConfig {} // only the key from the prioritized loaded appid will be retrieved @Configuration @EnableApolloConfig(value = {"FX.apollo", "application.yml"}, - multipleConfigs = {@MultipleConfig( appid = "ORDER_SERVICE", namespaces = {"ORDER.apollo"})} + multipleConfigs = {@MultipleConfig(appid = "ORDER_SERVICE", namespaces = {"ORDER.apollo"})} ) public class SomeAppConfig {} ``` diff --git a/docs/zh/client/java-sdk-user-guide.md b/docs/zh/client/java-sdk-user-guide.md index 87e4f322e4b..f3314696228 100644 --- a/docs/zh/client/java-sdk-user-guide.md +++ b/docs/zh/client/java-sdk-user-guide.md @@ -735,7 +735,7 @@ public class AnotherAppConfig {} // 新增支持了多appId和对应namespace的加载,注意使用多appId的情况下,key相同的情况,只会取优先加载appId的那一个key @Configuration @EnableApolloConfig(value = {"FX.apollo", "application.yml"}, - multipleConfigs = {@MultipleConfig( appid = "ORDER_SERVICE", namespaces = {"ORDER.apollo"})} + multipleConfigs = {@MultipleConfig(appid = "ORDER_SERVICE", namespaces = {"ORDER.apollo"})} ) public class SomeAppConfig {} ```