Publisher

Struct Publisher 

Source
pub struct Publisher { /* private fields */ }
Expand description

Publishes outgoing Dispatches to the RabbitMQ cluster.

Distinguishes single publishing (try_publish and publish) from batch publishing (try_publish_many and publish_many).

Also, distinguishes fail-fast publishing (try_publish and try_publish_many) from error-less publishing (publish and publish_many).

§Connection

This publisher delegates establishing connection and creation of Channels to Connector, which must be started before creating a publisher.

No more than one Channel is being kept by this publisher, and it is re-fetched whenever a connection issue is suspected.

§Configuration

All publishing configuration is off-loaded to Egress.

One important part of the egress configuration is ConfirmationLevel. This level has significant consequences for the publishing process, as described in its documentation.

§Publishing

Publishing a Dispatch to RabbitMQ is a two-step process:

  1. Transmit the dispatch payload over network to the broker.
  2. Confirm with the broker the successful reception of the message.

The transmission step plays out the same way regardless of the configuration. This publisher always transmits one dispatch at a time (there should be no benefit in transmitting dispatches in parallel in a single channel).

The confirmation step depends a lot on the confirmation level selected on the egress.

§Batch benefits

The publishing of a Dispatch may be a one-step or a two-step process depending on the confirmation level of this publisher’s Egress.

The first step (transmission of the message to the broker) does not benefit from batching since the messages are transmitted one at a time. However, the second step (confirmation with the broker), if executed, can benefit from the batch approach.

§Publishing API

The following four publishing methods are exposed.

All publishing methods return all Dispatches that were passed into them (both in the happy path and in the case of an error). It is up to the caller to then either drop the dispatches or use them for a different purpose (e.g., also publish them via a different Publisher).

§try_publish: single Dispatch, fail-fast

Attempts once to publish a single dispatch and returns an error as soon as something goes wrong.

§publish: single Dispatch, error-less

Repeatedly attempts to publish a single dispatch and returns only once the message is confirmed.

§try_publish_many: batch of Dispatches, fail-fast

Attempts once to publish a batch of dispatches and returns an error as soon as something goes wrong.

§publish_many: batch of Dispatches, error-less

Repeatedly attempts to publish a batch of dispatches and returns only once all the messages are confirmed.

Implementations§

Source§

impl Publisher

Source

pub fn new(gateway: Gateway, egress: Egress) -> Self

Creates and returns a new Publisher.

Source

pub fn start(handle: impl AsRef<Handle>, egress: Egress) -> Self

Starts a new Connector with the given Handle and uses it to create and return a new Publisher for the given Egress.

Source§

impl Publisher

Source

pub fn name(&self) -> &str

Reports the name of this Publisher.

Source§

impl Publisher

Source

pub async fn try_publish( &self, dispatch: impl Into<Dispatch>, ) -> PublishingResult

Attempts once to publish a single Dispatch and returns an error as soon as something goes wrong.

The provided dispatch is returned back to the caller, both in the happy path and in the case of an error.

This is a fail-fast version of the single-dispatch publishing. For the error-less approach, use publish.

Source

pub async fn publish(&self, dispatch: impl Into<Dispatch>) -> Dispatch

Repeatedly attempts to publish a single Dispatch and returns only once the message is confirmed.

The provided dispatch is returned back to the caller.

Note that the ConfirmationLevel on this publisher’s Egress will significantly affect the publishing semantics.

This is an error-less version of the single-dispatch publishing. For the fail-fast approach, use try_publish.

Source

pub async fn try_publish_many<I>(&self, dispatches: I) -> BatchPublishingResult
where I: IntoIterator, I::Item: Into<Dispatch>,

Attempts once to publish a batch of Dispatches and returns an error as soon as something goes wrong.

The provided dispatches are all returned back to the caller, both in the happy path and in the case of an error.

This is a fail-fast version of the batch publishing. For the error-less approach, use publish_many.

Source

pub async fn publish_many<I>(&self, dispatches: I) -> Vec<Dispatch>
where I: IntoIterator, I::Item: Into<Dispatch>,

Repeatedly attempts to publish a batch of Dispatches and returns only once all the messages are confirmed.

The provided dispatches are all returned back to the caller.

Note that the ConfirmationLevel on this publisher’s Egress will significantly affect the publishing semantics.

This is an error-less version of the batch publishing. For the fail-fast approach, use try_publish_many.

Auto Trait Implementations§

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,