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
impl ConnectedLapinBroker
Sourcepub fn server_spec(&self) -> ServerSpec
pub fn server_spec(&self) -> ServerSpec
The AsyncAPI server description of the connection this broker dialled.
Sourcepub async fn subscribe(
&self,
def: impl QueueDescriptor,
) -> Result<LapinSubscriber, AmqpError>
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).
Sourcepub fn publisher<P: LapinPublishPolicy>(&self, policy: P) -> P::Live
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(())
}Sourcepub fn requester(&self, policy: LapinRequest) -> LapinRequester
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
impl ConnectedBroker for ConnectedLapinBroker
Source§impl Debug for ConnectedLapinBroker
impl Debug for ConnectedLapinBroker
Source§impl DefaultPublish for ConnectedLapinBroker
impl DefaultPublish for ConnectedLapinBroker
Source§type Policy = LapinPublish
type Policy = LapinPublish
Source§impl PublishPolicy<ConnectedLapinBroker> for LapinPublish
impl PublishPolicy<ConnectedLapinBroker> for LapinPublish
Source§type Live = LapinPublisher
type Live = LapinPublisher
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>>
fn pair( self, connected: &ConnectedLapinBroker, ) -> impl Future<Output = Result<Self::Live, PairError>>
Source§fn channel_bindings(&self, destination: &str) -> Bindings
fn channel_bindings(&self, destination: &str) -> Bindings
AsyncAPI
document. Read moreSource§fn operation_bindings(&self, _destination: &str) -> Bindings
fn operation_bindings(&self, _destination: &str) -> Bindings
send operation in the document. Read moreSource§impl PublishPolicy<ConnectedLapinBroker> for ConfirmsPublish
impl PublishPolicy<ConnectedLapinBroker> for ConfirmsPublish
Source§type Live = ConfirmsPublisher
type Live = ConfirmsPublisher
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>>
fn pair( self, connected: &ConnectedLapinBroker, ) -> impl Future<Output = Result<Self::Live, PairError>>
Source§fn channel_bindings(&self, destination: &str) -> Bindings
fn channel_bindings(&self, destination: &str) -> Bindings
AsyncAPI
document. Read moreSource§fn operation_bindings(&self, _destination: &str) -> Bindings
fn operation_bindings(&self, _destination: &str) -> Bindings
send operation in the document. Read moreSource§impl PublishPolicy<ConnectedLapinBroker> for ServerTxPublish
impl PublishPolicy<ConnectedLapinBroker> for ServerTxPublish
Source§type Live = ServerTxPublisher
type Live = ServerTxPublisher
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>>
fn pair( self, connected: &ConnectedLapinBroker, ) -> impl Future<Output = Result<Self::Live, PairError>>
Source§fn channel_bindings(&self, destination: &str) -> Bindings
fn channel_bindings(&self, destination: &str) -> Bindings
AsyncAPI
document. Read moreSource§fn operation_bindings(&self, _destination: &str) -> Bindings
fn operation_bindings(&self, _destination: &str) -> Bindings
send operation in the document. Read moreSource§impl PublishPolicy<ConnectedLapinBroker> for LapinRequest
impl PublishPolicy<ConnectedLapinBroker> for LapinRequest
Source§type Live = LapinRequester
type Live = LapinRequester
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>>
fn pair( self, connected: &ConnectedLapinBroker, ) -> impl Future<Output = Result<Self::Live, PairError>>
Source§fn channel_bindings(&self, destination: &str) -> Bindings
fn channel_bindings(&self, destination: &str) -> Bindings
AsyncAPI
document. Read moreSource§fn operation_bindings(&self, _destination: &str) -> Bindings
fn operation_bindings(&self, _destination: &str) -> Bindings
send operation in the document. Read moreSource§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.
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
fn redelivery_address( &self, _connected: &ConnectedLapinBroker, ) -> impl Future<Output = Result<RedeliveryAddress, AmqpError>> + Send
Source§impl Subscribe for ConnectedLapinBroker
impl Subscribe for ConnectedLapinBroker
Source§type Copies = AddressedCopies
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>
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
type Subscriber = LapinSubscriber
Source§fn declare_retry(
&self,
name: &str,
declaration: &RetryDeclaration,
) -> Result<(), DeclareRetryError>
fn declare_retry( &self, name: &str, declaration: &RetryDeclaration, ) -> Result<(), DeclareRetryError>
Source§impl SubscriptionSource<ConnectedLapinBroker> for RabbitQueue
impl SubscriptionSource<ConnectedLapinBroker> for RabbitQueue
Source§type Copies = AddressedCopies
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
fn channel_bindings(&self) -> Bindings
The queue this subscription consumes, as the amqp binding names its settings.
Source§fn operation_bindings(&self) -> Bindings
fn operation_bindings(&self) -> Bindings
The consumer’s own half: this crate acknowledges by hand on every subscription.
Source§type Subscriber = LapinSubscriber
type Subscriber = LapinSubscriber
Source§async fn subscribe(
self,
connected: &ConnectedLapinBroker,
) -> Result<Self::Subscriber, AmqpError>
async fn subscribe( self, connected: &ConnectedLapinBroker, ) -> Result<Self::Subscriber, AmqpError>
Source§fn declare_retry(self, declaration: &RetryDeclaration) -> Selfwhere
Self: Sized,
fn declare_retry(self, declaration: &RetryDeclaration) -> Selfwhere
Self: Sized,
Source§fn declare_retry_on(
&self,
connected: &C,
declaration: &RetryDeclaration,
) -> Result<(), DeclareRetryError>
fn declare_retry_on( &self, connected: &C, declaration: &RetryDeclaration, ) -> Result<(), DeclareRetryError>
Source§fn message_bindings(&self) -> Bindings
fn message_bindings(&self) -> Bindings
Source§impl SubscriptionSource<ConnectedLapinBroker> for RabbitQuorumQueue
impl SubscriptionSource<ConnectedLapinBroker> for RabbitQuorumQueue
Source§type Copies = BrokerMoves
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
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
fn channel_bindings(&self) -> Bindings
The queue this subscription consumes, as the amqp binding names its settings.
Source§fn operation_bindings(&self) -> Bindings
fn operation_bindings(&self) -> Bindings
The consumer’s own half: this crate acknowledges by hand on every subscription.
Source§type Subscriber = LapinSubscriber
type Subscriber = LapinSubscriber
Source§async fn subscribe(
self,
connected: &ConnectedLapinBroker,
) -> Result<Self::Subscriber, AmqpError>
async fn subscribe( self, connected: &ConnectedLapinBroker, ) -> Result<Self::Subscriber, AmqpError>
Source§fn declare_retry_on(
&self,
connected: &C,
declaration: &RetryDeclaration,
) -> Result<(), DeclareRetryError>
fn declare_retry_on( &self, connected: &C, declaration: &RetryDeclaration, ) -> Result<(), DeclareRetryError>
Source§fn message_bindings(&self) -> Bindings
fn message_bindings(&self) -> Bindings
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.
impl TestableBroker for ConnectedLapinBroker
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>
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)
fn install_coordinator(&self, coordinator: Coordinator)
Source§fn inject(&self, message: OutgoingMessage<'_>)
fn inject(&self, message: OutgoingMessage<'_>)
Source§fn published(&self, name: &str) -> Vec<RawMessage>
fn published(&self, name: &str) -> Vec<RawMessage>
name on this broker, in publish order, after the
evicted ones. Backs the harness’s published::<T>(name) assertions and
expect_published.Source§fn backlog(&self) -> Backlog
fn backlog(&self) -> Backlog
Backlog::Missed for publish/subscribe,
Backlog::Delivered for a queue or a log that keeps them. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for ConnectedLapinBroker
impl !UnwindSafe for ConnectedLapinBroker
impl Freeze for ConnectedLapinBroker
impl Send for ConnectedLapinBroker
impl Sync for ConnectedLapinBroker
impl Unpin for ConnectedLapinBroker
impl UnsafeUnpin for ConnectedLapinBroker
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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