使用 Nacos 作为注册中心

使用 Nacos 作为注册中心

This example shows dubbo-go’s service discovery feature with Nacos as registry.

使用方式

通过以下方式指定注册中心地址:

  1. ins, _ := dubbo.NewInstance(
  2. dubbo.WithName("dubbo_registry_nacos_server"),
  3. dubbo.WithRegistry(
  4. registry.WithNacos(),
  5. registry.WithAddress("127.0.0.1:8848"),
  6. ),
  7. dubbo.WithProtocol(
  8. protocol.WithTriple(),
  9. protocol.WithPort(20000),
  10. ),
  11. )
  12. srv, err := ins.NewServer()

How to run

Start Nacos server

Follow this instruction to install and start Nacos server.

Run server

  1. $ go run ./go-server/cmd/server.go

test rpc server work as expected:

  1. $ curl \
  2. --header "Content-Type: application/json" \
  3. --data '{"name": "Dubbo"}' \
  4. http://localhost:20000/greet.GreetService/Greet

Open https://localhost:8848/nacos/ with browser, check url address successfully registered into Nacos.

Run client

  1. $ go run ./go-client/cmd/client.go
  2. hello world

最后修改 September 13, 2024: Refactor website structure (#2860) (1a4b998f54b)