pub struct ServiceClient { /* private fields */ }
Expand description
Standalone client for calling microservices from external applications
This is perfect for:
- API Gateway calling microservices
- Testing microservices
- Integration between different systems
Implementations§
Source§impl ServiceClient
impl ServiceClient
Sourcepub async fn new(
client_name: impl Into<String>,
amqp_url: impl Into<String>,
) -> Result<Self>
pub async fn new( client_name: impl Into<String>, amqp_url: impl Into<String>, ) -> Result<Self>
Create a new service client
Sourcepub async fn call(
&self,
service: impl Into<String>,
method: impl Into<String>,
params: impl Serialize,
) -> Result<RpcResponse>
pub async fn call( &self, service: impl Into<String>, method: impl Into<String>, params: impl Serialize, ) -> Result<RpcResponse>
Call a microservice method
This is how the API gateway calls microservices:
let client = ServiceClient::new("api-gateway", "amqp://localhost:5672").await?;
let response = client.call("user-service", "get_user", 123).await?;
Sourcepub async fn call_with_timeout(
&self,
service: impl Into<String>,
method: impl Into<String>,
params: impl Serialize,
timeout: Duration,
) -> Result<RpcResponse>
pub async fn call_with_timeout( &self, service: impl Into<String>, method: impl Into<String>, params: impl Serialize, timeout: Duration, ) -> Result<RpcResponse>
Call with custom timeout
Sourcepub async fn is_healthy(&self) -> bool
pub async fn is_healthy(&self) -> bool
Check if client is connected and healthy
Sourcepub async fn get_stats(&self) -> ClientStats
pub async fn get_stats(&self) -> ClientStats
Get client statistics
Trait Implementations§
Source§impl Clone for ServiceClient
impl Clone for ServiceClient
Source§fn clone(&self) -> ServiceClient
fn clone(&self) -> ServiceClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for ServiceClient
impl !RefUnwindSafe for ServiceClient
impl Send for ServiceClient
impl Sync for ServiceClient
impl Unpin for ServiceClient
impl !UnwindSafe for ServiceClient
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more