This example shows dubbo-go’s service discovery feature with Nacos as registry.
通过以下方式指定注册中心地址:
ins, _ := dubbo.NewInstance(
dubbo.WithName("dubbo_registry_nacos_server"),
dubbo.WithRegistry(
registry.WithNacos(),
registry.WithAddress("127.0.0.1:8848"),
),
dubbo.WithProtocol(
protocol.WithTriple(),
protocol.WithPort(20000),
),
)
srv, err := ins.NewServer()
Follow this instruction to install and start Nacos server.
$ go run ./go-server/cmd/server.go
test rpc server work as expected:
$ curl \
--header "Content-Type: application/json" \
--data '{"name": "Dubbo"}' \
http://localhost:20000/greet.GreetService/Greet
Open https://localhost:8848/nacos/
with browser, check url address successfully registered into Nacos.
$ go run ./go-client/cmd/client.go
hello world