mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 01:27:31 +08:00
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:
48
crates/external_services/src/grpc_client.rs
Normal file
48
crates/external_services/src/grpc_client.rs
Normal 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,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user