修改完善nacos熔断机制

This commit is contained in:
shiran
2025-05-19 17:26:18 +08:00
parent 64bda39e10
commit 916a8bf935
3 changed files with 75 additions and 5 deletions
+7 -4
View File
@@ -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
}