pub struct KafkaTopics { /* private fields */ }Expand description
A subscription to several topics, or to every topic matching a regex, through one consumer and one consumer group.
All matched topics share the handler, and therefore its payload type; each delivery still reports the topic it came from. Topics created after the group formed are picked up on the next metadata refresh of a pattern subscription.
One such subscription reads many destinations and a copy published to any one of them would
come back on the wrong topic, so this form leaves the retry destination to the mount site:
.out_retry(policy).to("orders.retry"), or a transform that names it per delivery. One
topic on its own is KafkaTopic, which addresses its own copies.
§Examples
use ruststream_rdkafka::prelude::*;
#[subscriber(KafkaTopics::new(["orders-eu", "orders-us"]).group("orders-svc"))]
async fn place(order: &Order, Ctx(topic): Ctx<Topic>) -> HandlerOutcome {
tracing::info!(order.id, %topic, "accepted");
HandlerOutcome::ack()
}
fn app() -> RustStream {
RustStream::new(AppInfo::new("orders", "0.1.0"))
.with_broker(KafkaBroker::new(["localhost:9092"]), |b| {
b.include(place);
})
}Implementations§
Source§impl KafkaTopics
impl KafkaTopics
Sourcepub fn new(topics: impl IntoIterator<Item = impl Into<String>>) -> Self
pub fn new(topics: impl IntoIterator<Item = impl Into<String>>) -> Self
Describes a subscription to every one of topics, by literal name.
Sourcepub fn pattern(pattern: impl Into<String>) -> Self
pub fn pattern(pattern: impl Into<String>) -> Self
Describes a subscription to every existing topic matching pattern.
The pattern is a librdkafka topic regex and must start with ^ (that anchor is how
librdkafka distinguishes a pattern from a literal name); subscribing fails with a clear
error otherwise.
§Examples
use ruststream_rdkafka::prelude::*;
#[subscriber(KafkaTopics::pattern("^audit\\..*").group("audit-svc"))]
async fn archive(event: &Event, Ctx(topic): Ctx<Topic>) -> HandlerOutcome {
tracing::info!(kind = %event.kind, %topic, "recorded");
HandlerOutcome::ack()
}
fn app() -> RustStream {
RustStream::new(AppInfo::new("audit", "0.1.0"))
.with_broker(KafkaBroker::new(["localhost:9092"]), |b| {
b.include(archive);
})
}Sourcepub fn and_topic(self, topic: impl Into<String>) -> Self
pub fn and_topic(self, topic: impl Into<String>) -> Self
Adds another literal topic to the same subscription.
Sourcepub fn and_pattern(self, pattern: impl Into<String>) -> Self
pub fn and_pattern(self, pattern: impl Into<String>) -> Self
Adds another ^-anchored topic regex to the same subscription.
Sourcepub fn group(self, group: impl Into<String>) -> Self
pub fn group(self, group: impl Into<String>) -> Self
The consumer group for this subscription, overriding
KafkaBroker::default_group.
Sourcepub fn start(self, start: StartOffset) -> Self
pub fn start(self, start: StartOffset) -> Self
Where the group starts when it has no committed offset (see StartOffset).
Sourcepub fn commit(self, commit: Commit) -> Self
pub fn commit(self, commit: Commit) -> Self
How processed deliveries are committed (see Commit).
Sourcepub fn assignment(self, assignment: Assignment) -> Self
pub fn assignment(self, assignment: Assignment) -> Self
The partition assignment strategy (see Assignment); unset means the librdkafka
default (range,roundrobin).
Sourcepub fn lane_key(self, lane_key: LaneKey) -> Self
pub fn lane_key(self, lane_key: LaneKey) -> Self
What drives keyed worker lanes for this subscription (see LaneKey).
Trait Implementations§
Source§impl Clone for KafkaTopics
impl Clone for KafkaTopics
Source§impl Debug for KafkaTopics
impl Debug for KafkaTopics
Source§impl IntoSource for KafkaTopics
impl IntoSource for KafkaTopics
Source§type Source = KafkaTopics
type Source = KafkaTopics
Source§fn into_source(self) -> Self
fn into_source(self) -> Self
Source§impl SubscriptionSource<ConnectedKafkaBroker> for KafkaTopics
impl SubscriptionSource<ConnectedKafkaBroker> for KafkaTopics
Source§type Subscriber = KafkaSubscriber
type Subscriber = KafkaSubscriber
Source§type Copies = NamedCopies
type Copies = NamedCopies
AddressedCopies, NamedCopies or BrokerMoves. Read moreSource§async fn subscribe(
self,
connected: &ConnectedKafkaBroker,
) -> Result<Self::Subscriber, KafkaError>
async fn subscribe( self, connected: &ConnectedKafkaBroker, ) -> Result<Self::Subscriber, KafkaError>
Source§fn operation_bindings(&self) -> Bindings
fn operation_bindings(&self) -> Bindings
receive operation in the document. Read moreSource§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 channel_bindings(&self) -> Bindings
fn channel_bindings(&self) -> Bindings
AsyncAPI document. Read moreSource§fn message_bindings(&self) -> Bindings
fn message_bindings(&self) -> Bindings
Auto Trait Implementations§
impl Freeze for KafkaTopics
impl RefUnwindSafe for KafkaTopics
impl Send for KafkaTopics
impl Sync for KafkaTopics
impl Unpin for KafkaTopics
impl UnsafeUnpin for KafkaTopics
impl UnwindSafe for KafkaTopics
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
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