Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add usage instructions for multiple appid in the Apollo client #5295

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/en/client/java-sdk-user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
22 changes: 22 additions & 0 deletions docs/zh/client/java-sdk-user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 配置
Expand Down Expand Up @@ -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及以上版本)。
Expand Down
Loading