Skip to main content

MessageBackend

Trait MessageBackend 

Source
pub trait MessageBackend: Send + Sync {
    // Required methods
    fn receive<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = WorkerResult<ReceiveResult<Value>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn ack<'life0, 'life1, 'async_trait>(
        &'life0 self,
        message_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = WorkerResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn nack<'life0, 'life1, 'async_trait>(
        &'life0 self,
        message_id: &'life1 str,
        requeue: bool,
    ) -> Pin<Box<dyn Future<Output = WorkerResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn health_check<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = WorkerResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn shutdown<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = WorkerResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Trait for message backend implementations.

Backends are responsible for receiving messages from external sources (RabbitMQ, Redis Streams, etc.) and providing acknowledgment handles.

Required Methods§

Source

fn receive<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = WorkerResult<ReceiveResult<Value>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Receive the next message with detailed status information.

This is the primary receive method that provides explicit semantics for different receive outcomes (shutdown, connection lost, retryable errors, etc.).

§Returns
  • Ok(ReceiveResult) - Contains the receive outcome
  • Err(WorkerError) - Fatal error occurred
Source

fn ack<'life0, 'life1, 'async_trait>( &'life0 self, message_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = WorkerResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Acknowledge a message by ID.

This is used for batch acknowledgments or when the AckHandle is not available. For single message acks, prefer using the AckHandle on ReceivedMessage.

§Arguments
  • message_id - The ID of the message to acknowledge
Source

fn nack<'life0, 'life1, 'async_trait>( &'life0 self, message_id: &'life1 str, requeue: bool, ) -> Pin<Box<dyn Future<Output = WorkerResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Negative acknowledge a message by ID.

§Arguments
  • message_id - The ID of the message to negative-acknowledge
  • requeue - If true, requeue the message for redelivery
Source

fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = WorkerResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Perform a health check on the backend.

§Returns
  • Ok(()) - Backend is healthy
  • Err(WorkerError) - Backend is unhealthy
Source

fn shutdown<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = WorkerResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Gracefully shutdown the backend.

This should stop accepting new messages and clean up resources.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§