xframe/component/agollo/readme.md

60 lines
1.9 KiB
Markdown
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Agollo客户端
## 使用
启动示例:
```go
package main
import (
"git.ixiaochuan.cn/zeus/xczero_frame/component/agollo"
"git.ixiaochuan.cn/zeus/xczero_frame/component/agollo/env/config"
)
func main() {
agollo.Start(&config.AppConfig{
AppID: "zuiyou",
Cluster: "search-server",
NamespaceName: "application",
IP: "172.20.20.2:8080",
})
}
```
*获取配置*
使用repository中的该方法
```go
package main
import (
"git.ixiaochuan.cn/zeus/xczero_frame/component/agollo"
)
func main() {
agollo.GetStringValue("config_key", "default_value")
agollo.GetBoolValue("config_key", true)
agollo.GetIntValue("config_key", 111)
agollo.GetFloatValue("config_key", 1.23)
}
```
## 结构
本客户端主要包含三个方面的内容更新分别为server_ips、notifications和apolloConfigs。
其中server_ips为单独一个协程来更新另外两个共用一个协程顺序按更新。
### server_ips
服务刚启动时客户端会根据配置中的hostport来访问metaserver服务
如果metaserver服务一直也没问题的话那么server_ips不会被访问到。当且仅当访问metaserver出错的时候会访问server_ips
也就是说server_ips是一个降级措施。
### notifications 和 apolloConfigs
notifications用于长轮询当服务端配置没有任何更新的时候此处长轮询会阻塞住根据服务端和客户端配置来设置阻塞时长。
客户端需设置超时时间大于服务端配置。当前客户端链接超时时间配置为10min服务端设置为长轮询1min后返回结果。
首次访问马上返回相应的配置。再次访问如果用户配置没有更新则notifications服务端返回HTTP状态码304不进行更新。
在长轮询结束后,无论如何都进行一次用户配置的更新,防止出现用户配置没有被正确更新的情况。(线上出现过这种问题)