1 pub mod hello_world { 2 tonic::include_proto!("helloworld"); 3 } 4 5 use hello_world::{greeter_client::GreeterClient, HelloRequest}; 6 7 #[tokio::main] main() -> Result<(), Box<dyn std::error::Error>>8async fn main() -> Result<(), Box<dyn std::error::Error>> { 9 tracing_subscriber::FmtSubscriber::builder() 10 .with_max_level(tracing::Level::DEBUG) 11 .init(); 12 13 say_hi("Bob".into()).await?; 14 15 Ok(()) 16 } 17 18 #[tracing::instrument] say_hi(name: String) -> Result<(), Box<dyn std::error::Error>>19async fn say_hi(name: String) -> Result<(), Box<dyn std::error::Error>> { 20 let mut client = GreeterClient::connect("http://[::1]:50051").await?; 21 22 let request = tonic::Request::new(HelloRequest { name }); 23 24 tracing::info!( 25 message = "Sending request.", 26 request = %request.get_ref().name 27 ); 28 29 let response = client.say_hello(request).await?; 30 31 tracing::info!( 32 message = "Got a response.", 33 response = %response.get_ref().message 34 ); 35 36 Ok(()) 37 } 38