Commit ad6f7ca0 authored by hujiebin's avatar hujiebin

Revert "feat:连上consul,才做服务发现"

This reverts commit fe793910.
parent d82a90c5
...@@ -103,33 +103,33 @@ func init() { ...@@ -103,33 +103,33 @@ func init() {
} }
mylogrus.MyLog.Infof("userCenterAddr:%v,addr:%v", userCenterAddr, addrs) mylogrus.MyLog.Infof("userCenterAddr:%v,addr:%v", userCenterAddr, addrs)
} }
resolver.Register(bd) // 服务注册 }
go func() { mylogrus.MyLog.Infof("connect userCenterAddr:%v", userCenterAddr)
address := consulapi.DefaultConfig().Address // 用consul api的default config resolver.Register(bd)
if err := consul.RegisterWatcher("services", nil, address, func(serviceStatus map[string]map[string][]string) { go func() {
if statusAddrs, ok := serviceStatus[userCenterConsulName]; ok { address := consulapi.DefaultConfig().Address // 用consul api的default config
healthAddrs, _ := statusAddrs[consulapi.HealthPassing] if err := consul.RegisterWatcher("services", nil, address, func(serviceStatus map[string]map[string][]string) {
l := len(healthAddrs) if statusAddrs, ok := serviceStatus[userCenterConsulName]; ok {
if l > 0 { healthAddrs, _ := statusAddrs[consulapi.HealthPassing]
mylogrus.MyLog.Infof("consul service update state:%v-%v", userCenterConsulName, healthAddrs) l := len(healthAddrs)
bd.UpdateState(healthAddrs) // 更新新的注册名 if l > 0 {
} else { mylogrus.MyLog.Infof("consul service update state:%v-%v", userCenterConsulName, healthAddrs)
mylogrus.MyLog.Warnf("consul service update local state:%v-%v", userCenterConsulName, defaultUserCenterAddr) bd.UpdateState(healthAddrs) // 更新新的注册名
bd.UpdateState([]string{defaultUserCenterAddr}) // 都没有健康的,使用默认本地回环的 } else {
} mylogrus.MyLog.Warnf("consul service update local state:%v-%v", userCenterConsulName, defaultUserCenterAddr)
for status := range statusAddrs { bd.UpdateState([]string{defaultUserCenterAddr}) // 都没有健康的,使用默认本地回环的
if status == consulapi.HealthPassing { }
continue for status := range statusAddrs {
} if status == consulapi.HealthPassing {
mylogrus.MyLog.Warnf("consul service wrong state:%v-%v-%v", userCenterConsulName, status, statusAddrs[status]) continue
} }
mylogrus.MyLog.Warnf("consul service wrong state:%v-%v-%v", userCenterConsulName, status, statusAddrs[status])
} }
}); err != nil {
mylogrus.MyLog.Errorf("启动 consul 的watch监控失败")
} }
}() }); err != nil {
} mylogrus.MyLog.Errorf("启动 consul 的watch监控失败")
mylogrus.MyLog.Infof("connect userCenterAddr:%v", userCenterAddr) }
}()
//userCenterAddr := services[0].Address + ":" + strconv.Itoa(services[0].ServicePort) //userCenterAddr := services[0].Address + ":" + strconv.Itoa(services[0].ServicePort)
//mylogrus.MyLog.Printf("Choose userCenter %s, %s, weights: %v\n", services[0].ID, userCenterAddr, services[0].ServiceWeights) //mylogrus.MyLog.Printf("Choose userCenter %s, %s, weights: %v\n", services[0].ID, userCenterAddr, services[0].ServiceWeights)
......
Markdown is supported
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