This example shows dubbo-go’s service discovery feature with Zookeeper as registry.
Specify the registry address as follows:
ins, _ := dubbo.NewInstance(
dubbo.WithName("dubbo_registry_nacos_server"),
dubbo.WithRegistry(
registry.WithZookeeper(),
registry.WithAddress("127.0.0.1:2181"),
),
dubbo.WithProtocol(
protocol.WithTriple(),
protocol.WithPort(20000),
),
)
srv, err := ins.NewServer()
This example relies on Zookeeper as the registry; follow the steps below to start a Zookeeper server first.
docker run --rm -p 2181:2181 zookeeper
or make -f $DUBBO_GO_SAMPLES_ROOT_PATH/build/Makefile docker-up
.$ go run ./go-server/cmd/server.go
Test RPC server works as expected:
$ curl \
--header "Content-Type: application/json" \
--data '{"name": "Dubbo"}' \
http://localhost:20000/greet.GreetService/Greet
Check URL address has been successfully registered into Zookeeper:
# Enter Zookeeper bin directory, for example '$HOST_PATH/apache-zookeeper-3.5.9-bin/bin'
$ ./zkCli.sh
[zk: localhost:2181(CONNECTED) 0] ls /services/dubbo_registry_zookeeper_server
[30.221.147.198:20000]
$ go run ./go-client/cmd/client.go
hello world