Implement Configuration API(level-2) with ctripcorp/apollo.
The mapping rule is:
Params in Configuration API | apollo schema |
---|---|
app_id | //ignore it when querying or subscribing,use app_id in config file instead |
group | namespace |
label | //append to key. So the actual key stored in apollo will be 'key@$label' |
tag | // put into another configuration item with json format |
The actual key stored in apollo will be key@$label
and the value will be raw value.
Tags will be stored in a special namespace sidecar_config_tags
,
with key=group@$key@$label
and value=
{
"tag1": "tag1value",
"tag2": "tag2value"
}
Q: Why not store value and tags in a single configuration item to reduce times of queries,like:
{
"value":"raw value",
"tags":{
"tag1":"tag1value",
"tag2":"tag2value"
}
}
A: Legacy systems using apollo can't migrate to our sidecar if we design like this.
-
Get and subscribe APIs are compatible.Users can easily put legacy systems onto our sidecar if they don't use save/delete APIs.Just keep
label
field blank in config.json,and the sidecar will use the raw key instead ofkey@$label
to interact with apollo. -
Save/delete APIs might be incompatible.The sidecar use fixed
cluster
field configurated in config.json and fixedenv
field in code,which means users can't passcluster
andenv
field as a parameter for save/delete API when they want to change some configuration items with other appid.
{
"config_store": {
"type": "apollo",
"address": [
"http://106.54.227.205:8080"
],
"metadata": {
"app_id": "testApplication_yang",
"cluster": "dev",
"namespace_name": "dubbo,product.joe",
"is_backup_config": true,
"secret": "6ce3ff7e96a24335a9634fe9abca6d51"
}
}
}
We are using the official maintained sdk, the others sdks you can find in this repo.
Some problems with the sdk:
- Users must declare all namespaces in AppConfig before connecting to the server and constructing a client,like:
c := &config.AppConfig{
AppID: "testApplication_yang",
Cluster: "dev",
IP: "http://106.54.227.205:8080",
NamespaceName: "dubbo", // declare before connecting to the server
IsBackupConfig: true,
Secret: "6ce3ff7e96a24335a9634fe9abca6d51",
}
client,err:=agollo.StartWithConfig(func() (*config.AppConfig, error) {
return c, nil
})
-
Nowhere to configurate
env
field. -
No save/delete API.
-
No bulk query API.
-
No sure about the concurrent safety.
-
Nowhere to configurate or use Apollo Meta Server
-
Not sure about the consistency property between local cache and backend database.
-
The two operations(set kv+set tags) are not transaction,which may cause inconsistency.
Configuration API | apollo sdk API |
---|---|
GetConfiguration | cache := client.GetConfigCache(c.NamespaceName) value,_ := client.Get("key") |
SaveConfiguration | use open API via http. update + commit |
DeleteConfiguration | use open API via http. delete + commit |
SubscribeConfiguration | https://github.com/apolloconfig/agollo/wiki/%E7%9B%91%E5%90%AC%E5%8F%98%E6%9B%B4%E4%BA%8B%E4%BB%B6 |
Subscribe all namespaces declared in config.json