pub struct ServerTxPublish(/* private fields */);Expand description
The server-transactional publish policy: same options as LapinPublish, pairing into
ServerTxPublisher.
Reached with LapinPublish::server_tx.
§Examples
use std::error::Error;
use ruststream_lapin::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Deserialize)]
struct Transfer {
from: u64,
to: u64,
cents: i64,
}
#[derive(Serialize, Outgoing)]
#[outgoing(name = "ledger.entry")]
struct Entry {
account: u64,
cents: i64,
}
// Both legs of a transfer become visible together, or neither does.
async fn post(
ledger: &impl TransactionalPublisher,
transfer: &Transfer,
) -> Result<(), Box<dyn Error + Send + Sync>> {
let debit = Entry {
account: transfer.from,
cents: -transfer.cents,
};
let credit = Entry {
account: transfer.to,
cents: transfer.cents,
};
let mut scope = ledger.begin().await?;
for entry in [debit, credit] {
if let Err(err) = scope.message(&entry).publish().await {
scope.abort().await?;
return Err(err.into());
}
}
scope.commit().await?;
Ok(())
}
#[subscriber("transfers")]
async fn book(
transfer: &Transfer,
Out(ledger): Out<impl TransactionalPublisher>,
) -> HandlerOutcome {
if post(ledger, transfer).await.is_err() {
return HandlerOutcome::retry();
}
HandlerOutcome::ack()
}
fn app() -> RustStream {
let broker = LapinBroker::new("amqp://localhost:5672");
let ledger = LapinPublish::default().exchange("ledger").server_tx();
RustStream::new(AppInfo::new("ledger", "0.1.0")).with_broker(broker, |b| {
b.include(book).out(DefaultSlot, ledger).build();
})
}Implementations§
Source§impl ServerTxPublish
impl ServerTxPublish
Sourcepub fn exchange(self, exchange: impl Into<String>) -> Self
pub fn exchange(self, exchange: impl Into<String>) -> Self
Publishes to exchange instead of the default exchange.
Sourcepub fn persistent(self, persistent: bool) -> Self
pub fn persistent(self, persistent: bool) -> Self
Whether messages are marked persistent (delivery mode 2). Defaults to true.
One message departs from this with the publish builder’s
persistent step.
Sourcepub fn priority(self, priority: u8) -> Self
pub fn priority(self, priority: u8) -> Self
The AMQP priority property messages carry. Unset by default, so the broker sees
no priority at all.
It only orders deliveries on a queue declared with x-max-priority. One message
departs from this with the publish builder’s
priority step.
Sourcepub fn expiration(self, ttl: Duration) -> Self
pub fn expiration(self, ttl: Duration) -> Self
The AMQP per-message expiration (TTL) messages carry: the broker drops one once
ttl has passed without it being consumed. Unset by default, so messages do not
expire.
One message departs from this with the publish builder’s
expiration step.
Trait Implementations§
Source§impl Clone for ServerTxPublish
impl Clone for ServerTxPublish
Source§impl Debug for ServerTxPublish
impl Debug for ServerTxPublish
Source§impl Default for ServerTxPublish
impl Default for ServerTxPublish
impl Eq for ServerTxPublish
Source§impl LapinPublishPolicy for ServerTxPublish
impl LapinPublishPolicy for ServerTxPublish
Source§fn bind(self, connected: &ConnectedLapinBroker) -> Self::Live
fn bind(self, connected: &ConnectedLapinBroker) -> Self::Live
Source§impl PartialEq for ServerTxPublish
impl PartialEq for ServerTxPublish
Source§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 moreimpl StructuralPartialEq for ServerTxPublish
Auto Trait Implementations§
impl Freeze for ServerTxPublish
impl RefUnwindSafe for ServerTxPublish
impl Send for ServerTxPublish
impl Sync for ServerTxPublish
impl Unpin for ServerTxPublish
impl UnsafeUnpin for ServerTxPublish
impl UnwindSafe for ServerTxPublish
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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