Skip to main content

ConnectedLapinBroker

Struct ConnectedLapinBroker 

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

The typed witness that Broker::connect succeeded: holds the live connection.

Everything connection-bound hangs off this value: subscriptions (Subscribe, subscribe), publishers (publisher), and requesters (requester). ConnectedBroker::shutdown consumes it, so a publish or subscribe after shutdown is a compile error for the owner of the handle.

Implementations§

Source§

impl ConnectedLapinBroker

Source

pub fn server_spec(&self) -> ServerSpec

The AsyncAPI server description of the connection this broker dialled.

Source

pub async fn subscribe( &self, def: impl QueueDescriptor, ) -> Result<LapinSubscriber, AmqpError>

Opens a subscription for def, declaring its topology first when the broker opted in.

Takes either queue descriptor: RabbitQueue or RabbitQuorumQueue.

§Errors

Returns AmqpError::Closed after shutdown, AmqpError::Declare when opted-in declaration fails, AmqpError::InvalidOptions for contradictory descriptor options and for a retry declaration this queue cannot carry, and AmqpError::Subscribe when the channel or consumer cannot be opened (for example the queue, or the waiting queue or delayed exchange its delay names, does not exist and declaration was not opted into).

Source

pub fn publisher<P: LapinPublishPolicy>(&self, policy: P) -> P::Live

A live publisher for policy.

LapinPublish pairs into the fire-and-forget publisher, ConfirmsPublish into the confirm-transactional one, and ServerTxPublish into the AMQP-server-transactional one. All three are cheap to build and cheap to clone.

§Examples
use std::error::Error;

use ruststream::Broker;
use ruststream_lapin::prelude::*;
use serde::Serialize;

#[derive(Serialize, Outgoing)]
#[outgoing(name = "order.placed")]
struct OrderPlaced {
    id: u64,
}

// A one-off backfill outside any service: connect, publish, confirm.
async fn backfill(ids: &[u64]) -> Result<(), Box<dyn Error>> {
    let connected = LapinBroker::new("amqp://localhost:5672").connect().await?;
    let events = connected.publisher(LapinPublish::default().exchange("events").confirms());
    for &id in ids {
        events.message(&OrderPlaced { id }).publish().await?;
    }
    Ok(())
}
Source

pub fn requester(&self, policy: LapinRequest) -> LapinRequester

A live request/reply client over RabbitMQ direct reply-to.

The requester half of LapinRequest; publisher accepts the same policy, this accessor only names the result.

Trait Implementations§

Source§

impl ConnectedBroker for ConnectedLapinBroker

Source§

async fn shutdown(self) -> Result<Self::Closed, Self::Error>

Closes the connection, consuming the connected form.

§Errors

Returns AmqpError::Connect when the close handshake fails.

Source§

type Error = AmqpError

The error type returned by connected-broker operations.
Source§

type Closed = ClosedLapinBroker

The terminal witness returned by shutdown. Read more
Source§

impl Debug for ConnectedLapinBroker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl DefaultPublish for ConnectedLapinBroker

Source§

type Policy = LapinPublish

The broker’s plain publish policy, constructible with its defaults.
Source§

impl PublishPolicy<ConnectedLapinBroker> for LapinPublish

Source§

type Live = LapinPublisher

The live form this policy pairs into: a Publisher for a leaf policy, or the live wiring form for a combinator stack (a typed publisher over a policy pairs into the same typed publisher over the live leaf).
Source§

fn pair( self, connected: &ConnectedLapinBroker, ) -> impl Future<Output = Result<Self::Live, PairError>>

Pairs the policy with a connected broker, producing the live publisher. Read more
Source§

fn channel_bindings(&self, destination: &str) -> Bindings

What a publish through this policy adds to its channel in the generated AsyncAPI document. Read more
Source§

fn operation_bindings(&self, _destination: &str) -> Bindings

What a publish through this policy adds to its send operation in the document. Read more
Source§

fn reply_address_location(&self) -> Option<&'static str>

Where a client finds the address of a reply this policy publishes, as a runtime expression. Read more
Source§

fn message_bindings(&self, channel: &str) -> Bindings

What a publish through this policy adds to the messages that leave through it. Read more
Source§

impl PublishPolicy<ConnectedLapinBroker> for ConfirmsPublish

Source§

type Live = ConfirmsPublisher

The live form this policy pairs into: a Publisher for a leaf policy, or the live wiring form for a combinator stack (a typed publisher over a policy pairs into the same typed publisher over the live leaf).
Source§

fn pair( self, connected: &ConnectedLapinBroker, ) -> impl Future<Output = Result<Self::Live, PairError>>

Pairs the policy with a connected broker, producing the live publisher. Read more
Source§

fn channel_bindings(&self, destination: &str) -> Bindings

What a publish through this policy adds to its channel in the generated AsyncAPI document. Read more
Source§

fn operation_bindings(&self, _destination: &str) -> Bindings

What a publish through this policy adds to its send operation in the document. Read more
Source§

fn reply_address_location(&self) -> Option<&'static str>

Where a client finds the address of a reply this policy publishes, as a runtime expression. Read more
Source§

fn message_bindings(&self, channel: &str) -> Bindings

What a publish through this policy adds to the messages that leave through it. Read more
Source§

impl PublishPolicy<ConnectedLapinBroker> for ServerTxPublish

Source§

type Live = ServerTxPublisher

The live form this policy pairs into: a Publisher for a leaf policy, or the live wiring form for a combinator stack (a typed publisher over a policy pairs into the same typed publisher over the live leaf).
Source§

fn pair( self, connected: &ConnectedLapinBroker, ) -> impl Future<Output = Result<Self::Live, PairError>>

Pairs the policy with a connected broker, producing the live publisher. Read more
Source§

fn channel_bindings(&self, destination: &str) -> Bindings

What a publish through this policy adds to its channel in the generated AsyncAPI document. Read more
Source§

fn operation_bindings(&self, _destination: &str) -> Bindings

What a publish through this policy adds to its send operation in the document. Read more
Source§

fn reply_address_location(&self) -> Option<&'static str>

Where a client finds the address of a reply this policy publishes, as a runtime expression. Read more
Source§

fn message_bindings(&self, channel: &str) -> Bindings

What a publish through this policy adds to the messages that leave through it. Read more
Source§

impl PublishPolicy<ConnectedLapinBroker> for LapinRequest

Source§

type Live = LapinRequester

The live form this policy pairs into: a Publisher for a leaf policy, or the live wiring form for a combinator stack (a typed publisher over a policy pairs into the same typed publisher over the live leaf).
Source§

fn pair( self, connected: &ConnectedLapinBroker, ) -> impl Future<Output = Result<Self::Live, PairError>>

Pairs the policy with a connected broker, producing the live publisher. Read more
Source§

fn channel_bindings(&self, destination: &str) -> Bindings

What a publish through this policy adds to its channel in the generated AsyncAPI document. Read more
Source§

fn operation_bindings(&self, _destination: &str) -> Bindings

What a publish through this policy adds to its send operation in the document. Read more
Source§

fn reply_address_location(&self) -> Option<&'static str>

Where a client finds the address of a reply this policy publishes, as a runtime expression. Read more
Source§

fn message_bindings(&self, channel: &str) -> Bindings

What a publish through this policy adds to the messages that leave through it. Read more
Source§

impl RedeliveryAddressed<ConnectedLapinBroker> for RabbitQueue

The queue name: on the default exchange a routing key addresses the queue that carries it, so that is where the runtime’s retry copy reaches this subscription again.

The answer holds for a retry publisher on the default exchange, which is what LapinPublish is unless configured otherwise. A publisher aimed at a topic or direct exchange reaches the queue only through a binding under this name, so bind it there or leave the retry publisher on the default exchange.

Source§

fn redelivery_address( &self, _connected: &ConnectedLapinBroker, ) -> impl Future<Output = Result<RedeliveryAddress, AmqpError>> + Send

Where a publish reaches this subscription again. Read more
Source§

impl Subscribe for ConnectedLapinBroker

Source§

type Copies = AddressedCopies

A queue name is an address as well as a subscription: on the default exchange a routing key addresses the queue that carries it, so the service publishes a delayed redelivery back under the name it subscribed to.

The copy reaches the queue as long as the retry publisher sends on the default exchange, which is what LapinPublish does unless exchange says otherwise; pointing that publisher at a topic exchange with no binding under the queue name would send the copy nowhere, so bind it there or leave the retry publisher on the default exchange.

Source§

async fn subscribe(&self, name: &str) -> Result<Self::Subscriber, Self::Error>

Subscribes to the queue name with descriptor defaults (durable, shared).

Source§

type Subscriber = LapinSubscriber

The subscriber type opened by a by-name subscription.
Source§

fn declare_retry( &self, name: &str, declaration: &RetryDeclaration, ) -> Result<(), DeclareRetryError>

Takes what a registration mounted by a bare name declared about its retries, before the subscription opens. Read more
Source§

impl SubscriptionSource<ConnectedLapinBroker> for RabbitQueue

Source§

type Copies = AddressedCopies

The service publishes the copies of a retry, and the queue name is where they go: on the default exchange a routing key addresses the queue that carries it.

A classic queue keeps no counter and has no delivery limit, so there is nothing on the server to end a retry loop; the runtime counts and the mount site names the publisher the copies leave through with out_retry(policy).

Source§

fn channel_bindings(&self) -> Bindings

The queue this subscription consumes, as the amqp binding names its settings.

Source§

fn operation_bindings(&self) -> Bindings

The consumer’s own half: this crate acknowledges by hand on every subscription.

Source§

type Subscriber = LapinSubscriber

The subscriber type this source opens.
Source§

fn name(&self) -> &str

The name (subject / channel) this subscription binds to. Read more
Source§

async fn subscribe( self, connected: &ConnectedLapinBroker, ) -> Result<Self::Subscriber, AmqpError>

Opens the subscription against the connected broker. Called once at startup. Read more
Source§

fn declare_retry(self, declaration: &RetryDeclaration) -> Self
where Self: Sized,

Takes the registration’s retry declaration into the descriptor, before the subscription opens. Read more
Source§

fn declare_retry_on( &self, connected: &C, declaration: &RetryDeclaration, ) -> Result<(), DeclareRetryError>

Carries the registration’s declaration to the broker, at the same point and before the subscription opens. Read more
Source§

fn message_bindings(&self) -> Bindings

What this subscription adds to the messages that arrive on it. Read more
Source§

impl SubscriptionSource<ConnectedLapinBroker> for RabbitQuorumQueue

Source§

type Copies = BrokerMoves

The queue moves a spent delivery itself: its x-delivery-limit counts the deliveries and its dead-letter route takes the message that runs out of them, with nothing published by this process. That is what makes out_retry(policy) a compile error here, and what keeps the cap holding while the service is down.

Source§

fn declare_retry(self, declaration: &RetryDeclaration) -> Self

Takes the registration’s cap and dead-letter destination into the descriptor, so the queue this broker declares carries them as topology.

Source§

fn channel_bindings(&self) -> Bindings

The queue this subscription consumes, as the amqp binding names its settings.

Source§

fn operation_bindings(&self) -> Bindings

The consumer’s own half: this crate acknowledges by hand on every subscription.

Source§

type Subscriber = LapinSubscriber

The subscriber type this source opens.
Source§

fn name(&self) -> &str

The name (subject / channel) this subscription binds to. Read more
Source§

async fn subscribe( self, connected: &ConnectedLapinBroker, ) -> Result<Self::Subscriber, AmqpError>

Opens the subscription against the connected broker. Called once at startup. Read more
Source§

fn declare_retry_on( &self, connected: &C, declaration: &RetryDeclaration, ) -> Result<(), DeclareRetryError>

Carries the registration’s declaration to the broker, at the same point and before the subscription opens. Read more
Source§

fn message_bindings(&self) -> Bindings

What this subscription adds to the messages that arrive on it. Read more
Source§

impl TestableBroker for ConnectedLapinBroker

Available on crate feature testing only.

The harness’s view of the in-process transport: what it injects, what it reads back, and the coordinator it counts the in-flight deliveries with.

§Panics

inject and published panic on a broker connected with connect: the harness drives only the connection connect_in_process produced, and a live connection has no log to read and no synchronous way to take a message.

Source§

fn routes(&self, destination: &str, subscriptions: &[&str]) -> Vec<usize>

A queue hands each message to one of its consumers, so a publish to a queue with two subscriptions is owed by one of them, never by both.

The broker’s default publisher sends on the default exchange, which routes by queue name, so the candidates are the subscriptions of destination’s name, in the order they opened. In process the answer is the consumer the transport’s rotation serves next. Against a server the pick is the server’s and not observable from here, so a live test opens one subscription per queue.

Against a server a publish through a named exchange is owed by the subscriptions whose queues the service bound to it: by the binding key on a direct exchange, by the pattern on a topic exchange, every one on a fanout exchange. A consistent-hash exchange hands a key to the one queue its hash picks, so every bound queue owes the publish until the first delivery of that key shows which one took it.

§Panics

Panics against a server when destination has more than one subscription: the harness would wait on a consumer the server may not have picked, and time out without saying why.

Source§

fn install_coordinator(&self, coordinator: Coordinator)

Installs the harness coordinator into this broker’s bus for a test run. Idempotent: a second install on the same broker is ignored.
Source§

fn inject(&self, message: OutgoingMessage<'_>)

Injects a message onto the bus as an external producer would, synchronously (no awaiting). Routes through the broker’s normal fanout, so it is recorded and counted like any publish. Read more
Source§

fn published(&self, name: &str) -> Vec<RawMessage>

Returns every message published to name on this broker, in publish order, after the evicted ones. Backs the harness’s published::<T>(name) assertions and expect_published.
Source§

fn evicted(&self, name: &str) -> usize

How many of the oldest messages published to name this broker no longer holds, so published starts after them. Read more
Source§

fn backlog(&self) -> Backlog

What a subscription opened by name receives of the messages published to that name before it opened, as the real broker answers it: Backlog::Missed for publish/subscribe, Backlog::Delivered for a queue or a log that keeps them. Read more

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> CompatExt for T

Source§

fn compat(self) -> Compat<T> ⓘ
where T: Sized,

Applies the Compat adapter by value. Read more
Source§

fn compat_ref(&self) -> Compat<&T> ⓘ

Applies the Compat adapter by shared reference. Read more
Source§

fn compat_mut(&mut self) -> Compat<&mut T> ⓘ

Applies the Compat adapter by mutable reference. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PublishedThrough<DefaultSlot> for T

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 = !

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

fn try_from(value: U) -> Result<T, !>

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<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