Skip to main content

Subscriber

Trait Subscriber 

Source
pub trait Subscriber: Send {
    type Message: IncomingMessage;
    type Error: StdError + Send + Sync + 'static;

    // Required method
    fn stream(
        &mut self,
    ) -> impl Stream<Item = Result<Self::Message, Self::Error>> + Send + '_;
}
Expand description

A consumer attached to one or more broker names.

Subscriber yields messages via a Stream, so users get back-pressure and integration with the rest of the futures ecosystem for free. Each yielded item is a broker-specific IncomingMessage that must be acknowledged.

§Cancel safety

Polling stream is cancel-safe: dropping the returned Stream between polls is allowed. Implementations must not buffer partially-decoded frames in &self state; if buffering is required, it belongs in &mut self.

Required Associated Types§

Source

type Message: IncomingMessage

The message type yielded by this subscriber.

Source

type Error: StdError + Send + Sync + 'static

The error type yielded by the stream when delivery fails.

Required Methods§

Source

fn stream( &mut self, ) -> impl Stream<Item = Result<Self::Message, Self::Error>> + Send + '_

Returns a stream of broker deliveries.

The stream terminates when the subscription is cancelled or the broker connection closes.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§