-
Notifications
You must be signed in to change notification settings - Fork 43
ms service discovery
YoyoFx edited this page Dec 8, 2020
·
5 revisions
app.NewWebHostBuilder().
UseConfiguration(configuration).
ConfigureServices(func(serviceCollection *dependencyinjection.ServiceCollection) {
// 依赖注入 Nacos 服务发现组件
serverdiscovery.UseNacos(serviceCollection)
}).Build().Run()
application:
name: demo_dev
metadata: "develop"
server_discovery:
type: "nacos"
metadata:
url: "localhost"
port: 8848
namespace: "public"
#group_name: ""
#clusters: [""]
新建一个Controller,并在GetSD函数中获取demo_dev服务的所有实例
type UserController struct {
mvc.ApiController
discoveryClient serverdiscovery.IServerDiscovery
}
func NewUserController(sd serverdiscovery.IServerDiscovery) *UserController {
return &UserController{ discoveryClient: sd}
}
func (controller UserController) GetSD() mvc.ApiResult {
serviceList := controller.discoveryClient.GetAllInstances("demo_dev")
return controller.OK(serviceList)
}