feat(routing): build gRPC Client Interface to initiate communication with other gRPC services (#5835)

Co-authored-by: prajjwalkumar17 <prajjwal.kumar@juspay.in>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Nishant Joshi <nishant.joshi@juspay.in>
This commit is contained in:
Amisha Prabhat
2024-09-18 13:52:19 +05:30
committed by GitHub
parent b2364414ed
commit 99f5933894
24 changed files with 691 additions and 33 deletions

View File

@ -0,0 +1,48 @@
/// Dyanimc Routing Client interface implementation
#[cfg(feature = "dynamic_routing")]
pub mod dynamic_routing;
use std::{fmt::Debug, sync::Arc};
#[cfg(feature = "dynamic_routing")]
use dynamic_routing::{DynamicRoutingClientConfig, RoutingStrategy};
use router_env::logger;
use serde;
/// Struct contains all the gRPC Clients
#[derive(Debug, Clone)]
pub struct GrpcClients {
/// The routing client
#[cfg(feature = "dynamic_routing")]
pub dynamic_routing: RoutingStrategy,
}
/// Type that contains the configs required to construct a gRPC client with its respective services.
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, Default)]
pub struct GrpcClientSettings {
#[cfg(feature = "dynamic_routing")]
/// Configs for Dynamic Routing Client
pub dynamic_routing_client: DynamicRoutingClientConfig,
}
impl GrpcClientSettings {
/// # Panics
///
/// This function will panic if it fails to establish a connection with the gRPC server.
/// This function will be called at service startup.
#[allow(clippy::expect_used)]
pub async fn get_grpc_client_interface(&self) -> Arc<GrpcClients> {
#[cfg(feature = "dynamic_routing")]
let dynamic_routing_connection = self
.dynamic_routing_client
.clone()
.get_dynamic_routing_connection()
.await
.expect("Failed to establish a connection with the Dynamic Routing Server");
logger::info!("Connection established with gRPC Server");
Arc::new(GrpcClients {
#[cfg(feature = "dynamic_routing")]
dynamic_routing: dynamic_routing_connection,
})
}
}