本文整理匯總了Golang中github.com/wfxiang08/rpc_proxy/zk.Topology.ProductServicesPath方法的典型用法代碼示例。如果您正苦於以下問題:Golang Topology.ProductServicesPath方法的具體用法?Golang Topology.ProductServicesPath怎麽用?Golang Topology.ProductServicesPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/wfxiang08/rpc_proxy/zk.Topology
的用法示例。
在下文中一共展示了Topology.ProductServicesPath方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewBackServices
func NewBackServices(poller *zmq.Poller, productName string, topo *zk.Topology) *BackServices {
// 創建BackServices
result := &BackServices{
Services: make(map[string]*BackService),
OfflineServices: make(map[string]*BackService),
poller: poller,
topo: topo,
}
var evtbus chan interface{} = make(chan interface{}, 2)
servicesPath := topo.ProductServicesPath()
path, e1 := topo.CreateDir(servicesPath) // 保證Service目錄存在,否則會報錯
fmt.Println("Path: ", path, "error: ", e1)
services, err := topo.WatchChildren(servicesPath, evtbus)
if err != nil {
log.Println("Error: ", err)
// TODO: 這個地方需要優化
panic("Reading Service List Failed")
}
go func() {
for true {
result.Lock()
for _, service := range services {
log.Println("Service: ", service)
if _, ok := result.Services[service]; !ok {
result.addBackService(service)
}
}
result.Unlock()
// 等待事件
<-evtbus
// 讀取數據,繼續監聽(連接過期了就過期了,再次Watch即可)
services, err = topo.WatchChildren(servicesPath, evtbus)
}
}()
// 讀取zk, 等待
log.Println("ProductName: ", result.topo.ProductName)
return result
}