Skip to main content

AmqpAddress

Struct AmqpAddress 

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

A subscription descriptor for an AMQP 1.0 address.

Implements SubscriptionSource, so it can sit inline in the #[subscriber(..)] decorator:

use ruststream_amqp::prelude::*;
use serde::Deserialize;

#[derive(Deserialize)]
struct Order {
    id: u64,
}

#[subscriber(AmqpAddress::queue("orders").credit(nonzero!(64)))]
async fn fulfil(order: &Order) -> HandlerOutcome {
    tracing::info!(order.id, "fulfilling");
    HandlerOutcome::ack()
}

Implementations§

Source§

impl AmqpAddress

Source

pub fn queue(name: impl Into<String>) -> Self

An anycast address: competing consumers, each message delivered to one of them.

§Examples
use ruststream_amqp::prelude::*;
use serde::Deserialize;

#[derive(Deserialize)]
struct Order {
    id: u64,
}

// Every replica of the service competes for "orders": each order is handled once.
#[subscriber(AmqpAddress::queue("orders"))]
async fn fulfil(order: &Order) -> HandlerOutcome {
    tracing::info!(order.id, "fulfilling");
    HandlerOutcome::ack()
}
Source

pub fn topic(name: impl Into<String>) -> Self

A multicast address: fan-out, each message delivered to every subscriber.

§Examples
use ruststream_amqp::prelude::*;
use serde::Deserialize;

#[derive(Deserialize)]
struct Event {
    kind: String,
}

// Every service subscribed to "events" gets its own copy of each event.
#[subscriber(AmqpAddress::topic("events"))]
async fn audit(event: &Event) -> HandlerOutcome {
    tracing::info!(kind = %event.kind, "audited");
    HandlerOutcome::ack()
}
Source

pub fn raw(address: impl Into<String>) -> Self

A verbatim address, for deployments with their own addressing convention ("/queues/orders" on RabbitMQ 4.x, a fully qualified queue on Artemis).

§Examples
use ruststream_amqp::prelude::*;
use serde::Deserialize;

#[derive(Deserialize)]
struct Order {
    id: u64,
}

// RabbitMQ 4.x addresses a queue by its v2 path; the string reaches the broker as written.
#[subscriber(AmqpAddress::raw("/queues/orders"))]
async fn fulfil(order: &Order) -> HandlerOutcome {
    tracing::info!(order.id, "fulfilling");
    HandlerOutcome::ack()
}
Source

pub fn credit(self, credit: NonZeroU32) -> Self

Sets the link credit: the window of deliveries the broker may send ahead of the handler’s settlements. Defaults to DEFAULT_CREDIT.

The subscription grants the full credit when it attaches, and grants it again each time half of it has been settled. The broker then never runs more than credit deliveries ahead of the last grant, but the deliveries held unsettled can outnumber the credit: with a credit of 4, the second settlement brings four more while two are still open.

The count is a NonZeroU32 because a subscription granted no credit receives nothing: zero is not a quieter setting but a stalled subscription, so it is unrepresentable here.

§Examples
use ruststream_amqp::prelude::*;
use serde::Deserialize;

#[derive(Deserialize)]
struct Order {
    id: u64,
}

// The broker sends up to 64 orders ahead of the handler's settlements.
#[subscriber(AmqpAddress::queue("orders").credit(nonzero!(64)))]
async fn fulfil(order: &Order) -> HandlerOutcome {
    tracing::info!(order.id, "fulfilling");
    HandlerOutcome::ack()
}

A zero is rejected while the service is compiled, not when the subscription opens:

ⓘ
use ruststream::nonzero;
use ruststream_amqp::AmqpAddress;

let source = AmqpAddress::queue("orders").credit(nonzero!(0));
Source

pub fn settle(self, settle: Settle) -> Self

Sets the delivery guarantee. Defaults to Settle::AtLeastOnce.

§Examples
use ruststream_amqp::prelude::*;
use serde::Deserialize;

#[derive(Deserialize)]
struct Event {
    kind: String,
}

// Settled on receipt: the audit may miss an event when the process stops, and the broker
// never waits for it.
#[subscriber(AmqpAddress::topic("events").settle(Settle::AtMostOnce))]
async fn audit(events: &[Event]) -> HandlerOutcome {
    for event in events {
        tracing::info!(kind = %event.kind, "audited");
    }
    HandlerOutcome::ack()
}

#[ruststream::app]
fn app() -> impl App {
    RustStream::new(AppInfo::new("audit", "0.1.0"))
        .with_broker(AmqpBroker::new("amqp://localhost:5672"), |b| {
            b.include(audit.batch(nonzero!(32)));
        })
}
Source

pub fn batch_wait(self, batch_wait: Duration) -> Self

Caps how long a partial batch waits for more deliveries on a batch subscription, counted from its first one. Defaults to DEFAULT_BATCH_WAIT.

AMQP 1.0 has no batch pull, so the batches are assembled on the client and this deadline is what trades latency for fuller batches under a trickle of traffic. It has no effect on a single-message subscription, where every delivery goes out as it arrives.

§Examples
use std::time::Duration;

use ruststream_amqp::prelude::*;
use serde::Deserialize;

#[derive(Deserialize)]
struct Order {
    id: u64,
}

// Up to 32 orders per call, or whatever arrived within 50 ms of the first one.
#[subscriber(AmqpAddress::queue("orders").batch_wait(Duration::from_millis(50)))]
async fn fulfil(orders: &[Order]) -> HandlerOutcome {
    tracing::info!(count = orders.len(), "fulfilling");
    HandlerOutcome::ack()
}

#[ruststream::app]
fn app() -> impl App {
    RustStream::new(AppInfo::new("orders", "0.1.0"))
        .with_broker(AmqpBroker::new("amqp://localhost:5672"), |b| {
            b.include(fulfil.batch(nonzero!(32)));
        })
}
Source

pub fn address(&self) -> &str

The address string sent to the broker.

Trait Implementations§

Source§

impl Clone for AmqpAddress

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AmqpAddress

Source§

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

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

impl Eq for AmqpAddress

Source§

impl IntoSource for AmqpAddress

The descriptor mounts on the manual path the way it does on the attribute: the subscriber(..) constructor takes it as its source, unchanged.

§Examples

use std::future::{Future, ready};

use ruststream_amqp::prelude::*;
use serde::Deserialize;

#[derive(Deserialize)]
struct Order {
    id: u64,
}

struct TakeOrder;

impl Handle<Order> for TakeOrder {
    fn handle(
        &self,
        order: &Order,
        _outs: &(),
        _ctx: &mut Context<'_>,
    ) -> impl Future<Output = Result<(), HandlerOutcome>> {
        tracing::info!(order.id, "order taken");
        ready(Ok(()))
    }
}

fn app() -> RustStream {
    RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(
        AmqpBroker::new("amqp://localhost:5672"),
        |b| {
            b.include(subscriber(AmqpAddress::queue("orders"), TakeOrder).build());
        },
    )
}
Source§

type Source = AmqpAddress

The source the constructor stores.
Source§

fn into_source(self) -> Self

Builds the source.
Source§

impl PartialEq for AmqpAddress

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl RedeliveryAddressed<ConnectedAmqpBroker> for AmqpAddress

Source§

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

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

impl StructuralPartialEq for AmqpAddress

Source§

impl SubscriptionSource<ConnectedAmqpBroker> for AmqpAddress

Source§

type Copies = AddressedCopies

AMQP 1.0 has no delayed redelivery and no wire-level way to declare a node with a delivery limit and a dead-letter address, so a spent delivery is this process’s to move: the runtime publishes the copies and this descriptor says where they land.

Source§

type Subscriber = AmqpSubscriber

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: &ConnectedAmqpBroker, ) -> Result<AmqpSubscriber, AmqpError>

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

fn channel_bindings(&self) -> Bindings

What this subscription adds to its channel in the generated AsyncAPI document. 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 operation_bindings(&self) -> Bindings

What this subscription adds to its receive operation in the document. Read more
Source§

fn message_bindings(&self) -> Bindings

What this subscription adds to the messages that arrive on it. 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<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> SendBound for T
where T: Send,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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