Skip to main content

Backend

Trait Backend 

Source
pub trait Backend:
    Send
    + Sync
    + 'static {
    // Required methods
    fn declare<'life0, 'life1, 'async_trait>(
        &'life0 self,
        queues: &'life1 [QueueConfig],
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn publish<'life0, 'life1, 'async_trait>(
        &'life0 self,
        envelope: &'life1 Envelope,
        delay: Option<Duration>,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn defer<'life0, 'life1, 'async_trait>(
        &'life0 self,
        envelope: &'life1 Envelope,
        delay: Duration,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn consume<'life0, 'life1, 'async_trait>(
        &'life0 self,
        queue: &'life1 QueueConfig,
    ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<Box<dyn Delivery>, Error>> + Send>>, Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn close<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
}
Expand description

A transport. Implementations: MemoryBackend (this crate), RabbitMqBackend.

Required Methods§

Source

fn declare<'life0, 'life1, 'async_trait>( &'life0 self, queues: &'life1 [QueueConfig], ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Idempotently create all queues (plus any retry / dead-letter infrastructure).

Source

fn publish<'life0, 'life1, 'async_trait>( &'life0 self, envelope: &'life1 Envelope, delay: Option<Duration>, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Publish envelope to envelope.queue, optionally delayed.

Source

fn defer<'life0, 'life1, 'async_trait>( &'life0 self, envelope: &'life1 Envelope, delay: Duration, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Publish envelope into a hold that releases it onto envelope.queue after delay. This is the publish half of Delivery::defer, also used by crate::Producer::defer.

Differs from publish with a delay only in intent, and backends may treat the two differently in detail: a deferral is expected to carry its queue’s top priority so it overtakes the backlog when it returns, and on RabbitMQ the delay is rounded to a separate, typically finer, granularity because a Retry-After is a contract while a backoff is a heuristic. Neither path releases a job early, and neither lets different delays block each other.

Hold naming and lifetime are backend-specific.

Source

fn consume<'life0, 'life1, 'async_trait>( &'life0 self, queue: &'life1 QueueConfig, ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<Box<dyn Delivery>, Error>> + Send>>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Start consuming queue with the given prefetch. The stream ends when the backend is closed or the connection is lost.

Source

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

Graceful shutdown: stop all consumers, flush, close connections.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§