1 pub mod pb { 2 tonic::include_proto!("grpc.examples.unaryecho"); 3 } 4 5 use pb::{echo_client::EchoClient, EchoRequest}; 6 use tonic::transport::Channel; 7 8 #[tokio::main] main() -> Result<(), Box<dyn std::error::Error>>9async fn main() -> Result<(), Box<dyn std::error::Error>> { 10 let endpoints = ["http://[::1]:50051", "http://[::1]:50052"] 11 .iter() 12 .map(|a| Channel::from_static(a)); 13 14 let channel = Channel::balance_list(endpoints); 15 16 let mut client = EchoClient::new(channel); 17 18 for _ in 0..12usize { 19 let request = tonic::Request::new(EchoRequest { 20 message: "hello".into(), 21 }); 22 23 let response = client.unary_echo(request).await?; 24 25 println!("RESPONSE={:?}", response); 26 } 27 28 Ok(()) 29 } 30