Calling from a gRPC Client
Consume the service.
The Generated Client
For each service tonic generates a client struct, for example GreeterClient, in the greeter_client module. It exposes one async method per rpc.
You construct it from a transport channel or by connecting directly to an endpoint.
use greeter::v1::greeter_client::GreeterClient;
use greeter::v1::HelloRequest;Connecting to a Server
The simplest path is GreeterClient::connect, which takes an address string and returns a connected client.
It runs inside an async context, so call it under #[tokio::main] with .await.
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = GreeterClient::connect("http://[::1]:50051").await?;
Ok(())
}All lessons in this course
- Protobuf and Service Definitions
- Generating Code with tonic-build
- Implementing a gRPC Server
- Calling from a gRPC Client