pub struct Buffered<S> { /* private fields */ }Expand description
A SubscriptionSource adapter that buffers the wrapped source’s subscriber into a
BatchSubscriber.
A batch closes when it holds the size the registration asked for, or once
max_wait has elapsed after its first delivery, whichever comes first; an
idle subscription waits indefinitely for that first delivery. The default deadline is 10 ms.
Under the testing harness, injecting through tb.message(&value).publish() drives the whole
reaction to a standstill before it returns, which closes the batch: one call per message yields
one batch per message, each holding a single element. A test that wants a longer batch takes a
producer handle off the broker before the app is built, publishes the run through it, and then
drives the reaction once with tb.settle().
§Examples
use std::time::Duration;
use ruststream::Buffered;
use ruststream::memory::prelude::*;
use ruststream::runtime::{Declared, SubscriberBuilder};
use serde::Deserialize;
/// A broker crate's mount-site step for a transport that delivers one message at a time: the
/// batches are assembled on the client, and a partial one closes `wait` after it opened.
pub trait Linger {
type Out;
fn linger(self, wait: Duration) -> Self::Out;
}
impl<Def: Declared, State, DefCodec> Linger
for SubscriberBuilder<Def, MemorySource, State, DefCodec>
{
type Out = SubscriberBuilder<Def, Buffered<MemorySource>, State, DefCodec>;
fn linger(self, wait: Duration) -> Self::Out {
self.map_source(|source| Buffered::new(source).max_wait(wait))
}
}
#[derive(Deserialize)]
struct Order {
id: u64,
}
#[subscriber(MemorySource)]
async fn settle(orders: &[Order]) -> HandlerOutcome {
tracing::info!(count = orders.len(), "settled a batch");
HandlerOutcome::ack()
}
fn app() -> RustStream {
RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(MemoryBroker::new(), |b| {
b.include(
settle
.name("orders")
.batch(nonzero!(64))
.linger(Duration::from_millis(20)),
);
})
}Implementations§
Trait Implementations§
Source§impl<C, S> RedeliveryAddressed<C> for Buffered<S>where
Self: SubscriptionSource<C, Copies = AddressedCopies>,
C: ConnectedBroker,
S: RedeliveryAddressed<C> + Send + Sync,
S::Subscriber: Send,
Batching happens on the client, so a retry copy goes where the wrapped source says it does.
impl<C, S> RedeliveryAddressed<C> for Buffered<S>where
Self: SubscriptionSource<C, Copies = AddressedCopies>,
C: ConnectedBroker,
S: RedeliveryAddressed<C> + Send + Sync,
S::Subscriber: Send,
Batching happens on the client, so a retry copy goes where the wrapped source says it does.
Source§fn redelivery_address(
&self,
connected: &C,
) -> impl Future<Output = Result<RedeliveryAddress, C::Error>> + Send
fn redelivery_address( &self, connected: &C, ) -> impl Future<Output = Result<RedeliveryAddress, C::Error>> + Send
Source§impl<C, S> SubscriptionSource<C> for Buffered<S>
impl<C, S> SubscriptionSource<C> for Buffered<S>
Source§fn declare_retry(self, declaration: &RetryDeclaration) -> Self
fn declare_retry(self, declaration: &RetryDeclaration) -> Self
Batching happens on the client, so the declaration reaches the wrapped source unchanged.
Source§fn declare_retry_on(
&self,
connected: &C,
declaration: &RetryDeclaration,
) -> Result<(), DeclareRetryError>
fn declare_retry_on( &self, connected: &C, declaration: &RetryDeclaration, ) -> Result<(), DeclareRetryError>
The same for the half of it the broker takes: batching is this process’s business.
Source§type Subscriber = BufferedSubscriber<<S as SubscriptionSource<C>>::Subscriber>
type Subscriber = BufferedSubscriber<<S as SubscriptionSource<C>>::Subscriber>
Source§type Copies = <S as SubscriptionSource<C>>::Copies
type Copies = <S as SubscriptionSource<C>>::Copies
AddressedCopies, NamedCopies or BrokerMoves. Read moreSource§async fn subscribe(self, connected: &C) -> Result<Self::Subscriber, C::Error>
async fn subscribe(self, connected: &C) -> Result<Self::Subscriber, C::Error>
Source§fn channel_bindings(&self) -> Bindings
fn channel_bindings(&self) -> Bindings
AsyncAPI document. Read moreSource§fn operation_bindings(&self) -> Bindings
fn operation_bindings(&self) -> Bindings
receive operation in the document. Read moreSource§fn message_bindings(&self) -> Bindings
fn message_bindings(&self) -> Bindings
Auto Trait Implementations§
impl<S> Freeze for Buffered<S>where
S: Freeze,
impl<S> RefUnwindSafe for Buffered<S>where
S: RefUnwindSafe,
impl<S> Send for Buffered<S>where
S: Send,
impl<S> Sync for Buffered<S>where
S: Sync,
impl<S> Unpin for Buffered<S>where
S: Unpin,
impl<S> UnsafeUnpin for Buffered<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for Buffered<S>where
S: UnwindSafe,
Blanket Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request