use crate::balance::load_balancer::RoundRobinLoadBalancer;
use tonic::transport::Channel;
pub struct GrpcClientBuilder {
service_name: String,
}
impl GrpcClientBuilder {
pub fn new(service_name: String) -> Self {
Self { service_name }
}
pub async fn build(&self) -> Result<Channel, crate::error::AppError> {
let balancer = RoundRobinLoadBalancer::new(self.service_name.clone());
balancer.build_channel().await
}
}
pub async fn create_grpc_channel(service_name: &str) -> Result<Channel, crate::error::AppError> {
GrpcClientBuilder::new(service_name.to_string())
.build()
.await
}
pub use create_grpc_channel as create_grpc_client;