Using Nacos as the Registry

Using Nacos as the Registry

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

Usage

Specify the registry address in the following way:

  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 if the RPC server works 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 a browser, check if the URL address is successfully registered into Nacos.

Run client

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

Feedback

Was this page helpful?

Yes No

Last modified September 30, 2024: Update & Translate Overview Docs (#3040) (d37ebceaea7)