修改完善nacos熔断机制
This commit is contained in:
@@ -10,8 +10,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
cli naming_client.INamingClient
|
||||
groupName string
|
||||
cli naming_client.INamingClient
|
||||
groupName string
|
||||
ServerUriCache = make(map[string]model.Instance)
|
||||
)
|
||||
|
||||
// NewNacosRegistry 创建一个nacos注册中心
|
||||
@@ -85,16 +86,18 @@ func DiscoverServiceList(serviceName string) ([]model.Instance, error) {
|
||||
|
||||
// DiscoverService 发现一个服务
|
||||
func DiscoverService(serviceName string) (model.Instance, error) {
|
||||
ServiceCache := ServerUriCache[serviceName]
|
||||
client, err := NewNacosRegistry()
|
||||
if err != nil {
|
||||
return model.Instance{}, err
|
||||
return ServiceCache, err
|
||||
}
|
||||
instances, err := (*client).SelectOneHealthyInstance(vo.SelectOneHealthInstanceParam{
|
||||
ServiceName: serviceName,
|
||||
GroupName: groupName,
|
||||
})
|
||||
if err != nil {
|
||||
return model.Instance{}, err
|
||||
return ServiceCache, err
|
||||
}
|
||||
ServerUriCache[serviceName] = *instances
|
||||
return *instances, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user