🛸 携程 apollo 配置中心客户端。支持查询配置、订阅配置、使用开放中心提供的公共 API。
npm install @vodyani/apollo-clientBase Usage
Advanced Usage
import { ApolloHttpClient } from '@vodyani/apollo-client'
const options = {
appId: 'your_apollo_app_id',
configServerUrl: 'your_apollo_config_server_url',
clusterName: 'your_apollo_cluster_name',
currentIp: 'your_server_ip',
secret: 'your_apollo_app_secret',
};
const httpClient = new ApolloHttpClient(options);options
- appId (require: ✅) apollo app id
- configServerUrl (require: ✅) apollo config server url
- clusterName (require: ❎) apollo app cluster name
- currentIp (require: ❎) your server ip
- secret (require: ❎) apollo app secret
const result = await httpClient.getConfig(
'your_apollo_namespace',
'properties'
)params
- namespace
stringapollo app namespace. (require: ✅) - type
NamespaceTypeapollo app namespace type. (require: ✅)
return
{
'your_apollo_namespace_key': 'your_apollo_namespace_value'
}- Other than txt, which returns text, all formats are deserialized as objects.
Call this method to access cached data.
const result = await httpClient.getConfigByCache(
'your_apollo_namespace',
'properties',
)params
- namespace
stringapollo app namespace. (require: ✅) - type
NamespaceTypeapollo app namespace type. (require: ✅)
return
{
'your_apollo_namespace_key': 'your_apollo_namespace_value'
}- Other than txt, which returns text, all formats are deserialized as objects.
Call this method to initiate a long poll that listens to the specified namespace and receives updates back from the server.
const result = await httpClient.getConfigNotifications([
{
namespace: 'your_apollo_namespace',
type: 'properties',
}
])params
- namespace
stringapollo app namespace. (require: ✅) - type
NamespaceTypeapollo app namespace type. (require: ✅)
return
[
{
namespaceName: 'your_apollo_namespace_name';
notificationId: 'your_apollo_notify_id',
},
]import { ApolloThirdPartyHttpClient } from '@vodyani/apollo-client'
const options = {
appId: 'your_apollo_app_id',
clusterName: 'your_apollo_cluster_name',
env: 'your_apollo_env',
secret: 'your_apollo_app_secret',
token: 'your_apollo_open_api_token',
portalServerUrl: 'your_apollo_portal_server_url',
operator: 'your_apollo_open_api_operator_user_name',
};
const thirdPartyOptions = new ApolloThirdPartyHttpClient(options);options
- appId (require: ✅) apollo app id
- env (require: ✅) apollo env
- token (require: ✅) apollo app open api token
- portalServerUrl (require: ✅) apollo portal server url
- operator (require: ✅) apollo open api operator user name
- clusterName (require: ❎) apollo app cluster name
const result = await thirdPartyOptions.getConfig(
'your_apollo_namespace',
'properties',
'your_apollo_namespace_property'
)
const result = await thirdPartyOptions.getConfig(
'your_apollo_namespace',
'json'
)params
- namespace
stringapollo app namespace. (require: ✅) - type
NamespaceTypeapollo app namespace type. (require: ✅) - key
stringapollo app namespace property, this parameter is mandatory only when typepropertiesis queried
return
{
'your_apollo_namespace_key': 'your_apollo_namespace_value'
}If you need to publish the configuration, don't forget to call it after execution
publishConfig
const result = await thirdPartyOptions.saveConfig(
'your_apollo_namespace',
'properties',
'your_apollo_namespace_property'
)
const result = await thirdPartyOptions.saveConfig(
'your_apollo_namespace',
'json'
)params
- namespace
stringapollo app namespace. (require: ✅) - type
NamespaceTypeapollo app namespace type. (require: ✅) - key
stringapollo app namespace property, this parameter is mandatory only when typepropertiesis queried
return
void
If you need to publish the configuration, don't forget to call it after execution
publishConfig
const result = await thirdPartyOptions.deleteConfig(
'your_apollo_namespace',
'properties',
'your_apollo_namespace_property'
)
const result = await thirdPartyOptions.deleteConfig(
'your_apollo_namespace',
'json'
)params
- namespace
stringapollo app namespace. (require: ✅) - type
NamespaceTypeapollo app namespace type. (require: ✅) - key
stringapollo app namespace property, this parameter is mandatory only when typepropertiesis queried
return
void
const result = await thirdPartyOptions.publishConfig(
'your_apollo_namespace',
'properties'
)
const result = await thirdPartyOptions.publishConfig(
'your_apollo_namespace',
'json'
)params
- namespace
stringapollo app namespace. (require: ✅) - type
NamespaceTypeapollo app namespace type. (require: ✅)
return
void
- properties ✅
- yaml ✅
- yml ✅
- json ✅
- txt ✅
- xml ❎
![]() |
|---|
| ChoGathK |
Vodyani apollo-client is MIT licensed.
