Using Zookeeper as a registry

Using Zookeeper as a registry

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

Usage

Specify the registry address as follows:

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

How to run

Start Zookeeper server

This example relies on Zookeeper as the registry; follow the steps below to start a Zookeeper server first.

  1. Start Zookeeper with Docker, run docker run --rm -p 2181:2181 zookeeper or make -f $DUBBO_GO_SAMPLES_ROOT_PATH/build/Makefile docker-up.
  2. Download and start Zookeeper locally on your machine.

Run server

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

Test RPC server works as expected:

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

Check URL address has been successfully registered into Zookeeper:

  1. # Enter Zookeeper bin directory, for example '$HOST_PATH/apache-zookeeper-3.5.9-bin/bin'
  2. $ ./zkCli.sh
  3. [zk: localhost:2181(CONNECTED) 0] ls /services/dubbo_registry_zookeeper_server
  4. [30.221.147.198:20000]

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)