Subscriber

Struct Subscriber 

Source
pub struct Subscriber<T, D>
where D: Decoder<Result = T>,
{ /* private fields */ }
Expand description

Receives incoming Envelopes from the RabbitMQ cluster, passing them through a pre-set Decoder before returning to the caller.

Implementations§

Source§

impl<T, D> Subscriber<T, D>
where D: Decoder<Result = T>,

Source

pub fn new(gateway: Gateway, ingress: Ingress, decoder: D) -> Self

Creates and returns a new Subscriber for the given Ingress and Decoder.

Source

pub fn start(handle: impl AsRef<Handle>, ingress: Ingress, decoder: D) -> Self

Starts a new Connector with the given Handle and uses it to create and return a new Subscriber for the given Ingress and Decoder.

Source§

impl<T, D> Subscriber<T, D>
where D: Decoder<Result = T>,

Source

pub fn name(&self) -> &str

Reports the name of this Subscriber.

Source§

impl Subscriber<(), NoopDecoder>

Source

pub fn new_undecoded(gateway: Gateway, ingress: Ingress) -> Self

A shorthand for calling new with a NoopDecoder.

Source

pub fn start_undecoded(handle: &Handle, ingress: Ingress) -> Self

A shorthand for calling start with a NoopDecoder.

Source§

impl<T, D> Subscriber<T, D>
where D: Decoder<Result = T>,

Source

pub async fn try_declare(&self) -> Result<(), DeclarationError>

Waits for the connection to RabbitMQ to become available, then issues the declarations necessary for consuming messages with the Ingress configured on this subscriber. The declarations include declaring an exchange (if not a built-in exchange), declaring a queue, and binding the queue to the exchange in some way. Such declarations are repeatable (assuming the configuration options don’t change), so it shouldn’t hurt to call this method any number of times.

If and when this method returns Ok, it can be reasonably expected that the following calls to receive or receive_many will be able to eventually deliver incoming messages, assuming the connectivity to RabbitMQ remains.

If any of the declarations fail (e.g., a queue by that name already exists with different configuration), this method returns a DeclarationError.

Source

pub async fn declare(&self)

Repeatedly calls try_declare until it succeeds, with an exponential backoff.

Most declaration errors can only be fixed outside the application, by changing the broker configuration (e.g., deleting a conflicting queue). In such cases, this method may be used, to keep the subscriber spinning (and alerting about the declaration failure) until the issue is fixed externally, at which point the declarations will eventually succeed, and this method will return.

Source

pub async fn receive(&self) -> Envelope<T>

Receives a single, decode-able message from the broker. Will wait as long as it takes for the first decode-able message to arrive.

Source

pub async fn receive_many(&self) -> NonEmpty<Envelope<T>>

Receives a batch of up to batch_size of decode-able messages from the broker. Will wait as long as it takes for the first decode-able message to arrive, after which will take no longer than [BATCH_TIMEOUT] to complete the batch before returning. The final batch will thus always contain at least one message.

Auto Trait Implementations§

§

impl<T, D> !Freeze for Subscriber<T, D>

§

impl<T, D> !RefUnwindSafe for Subscriber<T, D>

§

impl<T, D> Send for Subscriber<T, D>
where D: Send,

§

impl<T, D> Sync for Subscriber<T, D>
where D: Sync,

§

impl<T, D> Unpin for Subscriber<T, D>
where D: Unpin,

§

impl<T, D> !UnwindSafe for Subscriber<T, D>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,