MessageHandler

Trait MessageHandler 

Source
pub trait MessageHandler: Send + Sync {
    type MessageType: for<'de> Deserialize<'de> + Send + Sync;

    // Required methods
    fn handle_message<'life0, 'async_trait>(
        &'life0 self,
        message: Self::MessageType,
    ) -> Pin<Box<dyn Future<Output = Result<(), WorkerError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn handler_name(&self) -> &str;
}
Expand description

A trait for processing messages from a RabbitMQ queue.

Implement this trait for your specific message type and business logic.

Required Associated Types§

Source

type MessageType: for<'de> Deserialize<'de> + Send + Sync

The type of the message that this handler can process. Must be deserializable from JSON.

Required Methods§

Source

fn handle_message<'life0, 'async_trait>( &'life0 self, message: Self::MessageType, ) -> Pin<Box<dyn Future<Output = Result<(), WorkerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Processes a single deserialized message.

§Arguments
  • message - The deserialized message payload.
§Returns

Ok(()) if the message was processed successfully, or a WorkerError if not.

Source

fn handler_name(&self) -> &str

A name for the handler, used for logging and identification.

Implementors§