Skip to content

Latest commit

 

History

History

examples

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Consul conducted services Demo

This example demonstrates how to use consul as Service Registry and Discovery Center. The example includes a simple client and server program.

Prerequisites

  1. Consul in local host, use default port 8500. See https://developer.hashicorp.com/consul/docs/install.
  2. Bazel

File Structure

$ 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

Service Config

  • 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

Running the Example

  • 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