This example demonstrates how to use consul as Service Registry and Discovery Center. The example includes a simple client and server program.
- Consul in local host, use default port 8500. See https://developer.hashicorp.com/consul/docs/install.
- Bazel
$ tree examples
examples
├── client
│ ├── BUILD
│ ├── client.cc
│ └── trpc_cpp_fiber.yaml
├── README.md
└── server
├── BUILD
├── greeter_service.cc
├── greeter_service.h
├── helloworld.proto
├── helloworld_server.cc
└── trpc_cpp_fiber.yaml
-
Server
Config Consul address in plugins.registry section, like this:
plugins: registry: consul: address: 127.0.0.1:8500
-
Client
Config Consul address in plugins.selector section, like this:
plugins: selector: consul: address: 127.0.0.1:8500
-
Build and run server and client program
cd ../ ./run_example.sh
-
Compilation
We can run the following command to compile the demo.
bazel build //examples/...
-
Run the server program.
We can run the following command to start the server program.
./bazel-bin/examples/server/helloworld_server --config=examples/server/trpc_cpp_fiber.yaml
-
Run the client program
We can run the following command to start the client program.
./bazel-bin/examples/client/client --config=examples/client/trpc_cpp_fiber.yaml