Skip to content
Snippets Groups Projects
Commit 51831409 authored by 邹毅贤's avatar 邹毅贤
Browse files

update apollo

parent 7598e14d
No related branches found
No related tags found
No related merge requests found
......@@ -33,10 +33,10 @@ import (
)
const (
apolloEnvKey = "env";
apolloAddrKey = "apollo.meta";
apolloClusterKey = "apollo.cluster";
apolloProtocolPrefix = "http://";
apolloEnvKey = "env"
apolloAddrKey = "apollo.meta"
apolloClusterKey = "apollo.cluster"
apolloProtocolPrefix = "http://"
)
type apolloDynamicConfiguration struct {
......@@ -51,7 +51,7 @@ func newApolloDynamicConfiguration(url *common.URL) (*apolloDynamicConfiguration
c := &apolloDynamicConfiguration{
url: url,
}
configEnv := url.GetParam(apolloEnvKey, "");
configEnv := url.GetParam(apolloEnvKey, "")
configAddr := c.getAddressWithProtocolPrefix(url)
configCluster := url.GetParam(constant.CONFIG_GROUP_KEY, "")
if len(configEnv) != 0 {
......@@ -81,24 +81,30 @@ func newApolloDynamicConfiguration(url *common.URL) (*apolloDynamicConfiguration
return c, nil
}
func (c *apolloDynamicConfiguration) start() {
for event := range agollo.ListenChangeEvent() {
for name, change := range event.Changes {
cfgChangeEvent := &config_center.ConfigChangeEvent{
Key: name,
Value: change.NewValue,
ConfigType: c.getChangeType(change.ChangeType),
}
c.listeners.Range(func(key, value interface{}) bool {
for listener, _ := range value.(apolloListener).listeners {
listener.Process(cfgChangeEvent)
}
return true
})
type apolloChangeListener struct {
c *apolloDynamicConfiguration
}
func (a *apolloChangeListener) OnChange(event *agollo.ChangeEvent) {
for name, change := range event.Changes {
cfgChangeEvent := &config_center.ConfigChangeEvent{
Key: name,
Value: change.NewValue,
ConfigType: a.c.getChangeType(change.ChangeType),
}
a.c.listeners.Range(func(key, value interface{}) bool {
for listener, _ := range value.(apolloListener).listeners {
listener.Process(cfgChangeEvent)
}
return true
})
}
}
func (c *apolloDynamicConfiguration) start() {
agollo.AddChangeListener(&apolloChangeListener{})
}
func (c *apolloDynamicConfiguration) getChangeType(change agollo.ConfigChangeType) remoting.EventType {
switch change {
case agollo.ADDED:
......
......@@ -6,8 +6,6 @@ require (
github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190802083043-4cd0c391755e // indirect
github.com/apache/dubbo-go-hessian2 v1.2.5-0.20191029001541-894e45c9aaaa
github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/coocood/freecache v1.1.0 // indirect
github.com/coreos/bbolt v1.3.3 // indirect
github.com/coreos/etcd v3.3.13+incompatible
github.com/coreos/go-semver v0.3.0 // indirect
......@@ -46,7 +44,7 @@ require (
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect
github.com/toolkits/concurrent v0.0.0-20150624120057-a4371d70e3e3 // indirect
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
github.com/zouyx/agollo v1.8.0
github.com/zouyx/agollo v0.0.0-20191028150957-a5bd2d53f93d
go.etcd.io/bbolt v1.3.3 // indirect
go.etcd.io/etcd v3.3.13+incompatible
go.uber.org/atomic v1.4.0
......
......@@ -461,6 +461,7 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
github.com/tebeka/strftime v0.1.3 h1:5HQXOqWKYRFfNyBMNVc9z5+QzuBtIXy03psIhtdJYto=
github.com/tebeka/strftime v0.1.3/go.mod h1:7wJm3dZlpr4l/oVK0t1HYIc4rMzQ2XJlOMIUJUJH6XQ=
github.com/tent/http-link-go v0.0.0-20130702225549-ac974c61c2f9/go.mod h1:RHkNRtSLfOK7qBTHaeSX1D6BNpI3qw7NTxsmNr4RvN8=
github.com/tevid/gohamcrest v1.1.1/go.mod h1:3UvtWlqm8j5JbwYZh80D/PVBt0mJ1eJiYgZMibh0H/k=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 h1:LnC5Kc/wtumK+WB441p7ynQJzVuNRJiqddSIE3IlSEQ=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/toolkits/concurrent v0.0.0-20150624120057-a4371d70e3e3 h1:kF/7m/ZU+0D4Jj5eZ41Zm3IH/J8OElK1Qtd7tVKAwLk=
......@@ -471,8 +472,7 @@ github.com/vmware/govmomi v0.18.0 h1:f7QxSmP7meCtoAmiKZogvVbLInT+CZx6Px6K5rYsJZo
github.com/vmware/govmomi v0.18.0/go.mod h1:URlwyTFZX72RmxtxuaFL2Uj3fD1JTvZdx59bHWk6aFU=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/zouyx/agollo v1.8.0 h1:u2Z+zsSOUND9mZlKYSWGvxkRKZyRcBe+wK+mfBxYWv8=
github.com/zouyx/agollo v1.8.0/go.mod h1:4JiqkUebtrabKqJ9OBbgRlRvtvOKIeMUhNqd5qVvqqM=
github.com/zouyx/agollo v0.0.0-20191028150957-a5bd2d53f93d/go.mod h1:S1cAa98KMFv4Sa8SbJ6ZtvOmf0VlgH0QJ1gXI0lBfBY=
go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/etcd v3.3.13+incompatible h1:jCejD5EMnlGxFvcGRyEV4VGlENZc7oPQX6o0t7n3xbw=
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment