Set of examples that show off the features provided by tonic and grpc.
In order to build these examples, you must have the protoc Protocol Buffers
compiler. You need to have installed either:
-
the
protocbinary, made available in your PATH. This is the default. -
A compatible C++ compiler and CMake as described in the
protoc-gen-rust-grpccrate. Choose this option by passing--features protoc-gen-rust-grpctocargo.
If you choose to install protobuf, here are the steps for a variety of operating systems.
Ubuntu:
sudo apt update && sudo apt upgrade -y
sudo apt install -y protobuf-compiler libprotobuf-devAlpine Linux:
sudo apk add protoc protobuf-devmacOS:
Assuming Homebrew is already installed. (If not, see instructions for installing Homebrew on the Homebrew website.)
brew install protobufFor the examples related to the grpc crate, the generated code is checked into
the repo to allow building without protoc. To rebuild the generated code you
must set GRPC_RUST_REGENERATE_PROTO=1 in your environment. This requires that
you have installed either:
-
the
protocandprotoc-gen-rust-grpcbinaries, made available in your PATH. See above forprotoc.protoc-gen-rust-grpccan be downloaded from our releases. -
A compatible C++ compiler and CMake as described in the
protoc-gen-rust-grpccrate. Choose this option by passing--features grpc-protobuf-build/build-plugintocargo.
$ cargo run --bin grpc-helloworld-clientThe grpc crate currently does not support servers; run the Tonic helloworld
server instead:
$ cargo run --bin helloworld-server$ cargo run --bin grpc-routeguide-clientThe grpc crate currently does not support servers; run the Tonic routeguide
server instead:
$ cargo run --bin routeguide-server$ cargo run --bin helloworld-client$ cargo run --bin helloworld-server$ cargo run --bin routeguide-client$ cargo run --bin routeguide-server$ cargo run --bin authentication-client$ cargo run --bin authentication-server$ cargo run --bin load-balance-client$ cargo run --bin load-balance-server$ cargo run --bin dynamic-load-balance-client$ cargo run --bin dynamic-load-balance-server$ cargo run --bin tls-client$ cargo run --bin tls-server$ cargo run --bin health-server$ cargo run --bin reflection-server$ cargo run --bin tower-serversystemfd --no-pid -s http::[::1]:50051 -- cargo watch -x 'run --bin autoreload-server'If you are using the codegen feature, then the following dependencies are
required:
The autoload example requires the following crates installed globally:
Both clients and both servers do the same thing, but using the two different approaches. Run one of the servers in one terminal, and then run the clients in another.
$ cargo run --bin richer-error-client$ cargo run --bin richer-error-client-vec$ cargo run --bin richer-error-server$ cargo run --bin richer-error-server-vec