Skip to main content

MicroserviceClient

Trait MicroserviceClient 

Source
pub trait MicroserviceClient:
    Send
    + Sync
    + 'static {
    // Required methods
    fn send<Payload, Response>(
        &self,
        pattern: impl Into<String>,
        payload: Payload,
    ) -> Pin<Box<dyn Future<Output = Result<Response>> + Send>>
       where Payload: Serialize + Send + 'static,
             Response: DeserializeOwned + Send + 'static;
    fn emit<Payload>(
        &self,
        pattern: impl Into<String>,
        payload: Payload,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send>>
       where Payload: Serialize + Send + 'static;
}
Expand description

MicroserviceClient Trait

Defines the interface for sending messages and emitting events to microservices. Implement this trait to create custom transport adapters (e.g., TCP, Redis, NATS).

§Methods

  • send: Sends a request-response style message and waits for a response
  • emit: Sends an event (fire-and-forget) without waiting for a response

§Type Parameters

  • Payload: The message payload type (must be serializable)
  • Response: The response type (must be deserializable)

Required Methods§

Source

fn send<Payload, Response>( &self, pattern: impl Into<String>, payload: Payload, ) -> Pin<Box<dyn Future<Output = Result<Response>> + Send>>
where Payload: Serialize + Send + 'static, Response: DeserializeOwned + Send + 'static,

Sends a message and waits for a response.

§Arguments
  • pattern: The microservice pattern/endpoint to call
  • payload: The message payload to send
§Returns

A future that resolves to the response from the microservice.

Source

fn emit<Payload>( &self, pattern: impl Into<String>, payload: Payload, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send>>
where Payload: Serialize + Send + 'static,

Emits an event without waiting for a response.

§Arguments
  • pattern: The event pattern to emit
  • payload: The event payload to send
§Returns

A future that completes when the event is sent.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§