Files
tonic/tonic-examples/src/multiplex/client.rs
T
Lucio FrancoandGitHub 5c2f4dba32 feat(transport): Change channel connect to be async (#107)
This makes it so you can check if the initial connection
is established. Before this we used reconnect which would
lazily attempt to connect. So if you were trying to connect
to a non existant Server you wouldn't find out until after
you attempted your first RPC. This simplifies everything
by allowing you connect before creating the RPC client.

BREAKING CHANGE: `Endpoint::channel` was removed in favor of
an async `Endpoint::connect`.
2019-10-31 14:09:40 -04:00

40 lines
978 B
Rust

pub mod hello_world {
tonic::include_proto!("helloworld");
}
pub mod echo {
tonic::include_proto!("grpc.examples.echo");
}
use echo::{client::EchoClient, EchoRequest};
use hello_world::{client::GreeterClient, HelloRequest};
use tonic::transport::Endpoint;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let channel = Endpoint::from_static("http://[::1]:50051")
.connect()
.await?;
let mut greeter_client = GreeterClient::new(channel.clone());
let mut echo_client = EchoClient::new(channel);
let request = tonic::Request::new(HelloRequest {
name: "Tonic".into(),
});
let response = greeter_client.say_hello(request).await?;
println!("GREETER RESPONSE={:?}", response);
let request = tonic::Request::new(EchoRequest {
message: "hello".into(),
});
let response = echo_client.unary_echo(request).await?;
println!("ECHO RESPONSE={:?}", response);
Ok(())
}