pub struct KafkaTopic { /* private fields */ }Expand description
A subscription to one Kafka topic through one consumer group.
Everything except the topic name is optional; unset options fall back to the librdkafka
defaults (this crate does not impose its own). The group can also come from
KafkaBroker::default_group; a subscription that ends
up with no group at all is a startup error, because Kafka cannot subscribe without one.
This is the form a deferred retry_after copy can be published back to: one topic, and a
publish to it reaches every group reading it. Several topics at once take
KafkaTopics and named partitions take
KafkaPartitions; neither can be reached by a single publish, so
the mount site names where their copies go.
§Examples
use ruststream_rdkafka::prelude::*;
#[subscriber(
KafkaTopic::new("orders")
.group("orders-svc")
.start(StartOffset::Earliest)
.commit(Commit::Tracked)
.assignment(Assignment::CooperativeSticky)
.config("fetch.min.bytes", "1024")
)]
async fn place(order: &Order) -> HandlerOutcome {
tracing::info!(order.id, "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 KafkaTopic
impl KafkaTopic
Sourcepub fn new(topic: impl Into<String>) -> Self
pub fn new(topic: impl Into<String>) -> Self
Describes a subscription to topic with librdkafka defaults for everything else.
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); the default
lanes by the source partition, Kafka’s native ordering unit.
§Examples
Per-record-key lanes: one tenant’s orders never run concurrently, different tenants in one partition do.
use ruststream_rdkafka::prelude::*;
#[subscriber(
KafkaTopic::new("orders")
.group("orders-svc")
.commit(Commit::Tracked)
.lane_key(LaneKey::RecordKey),
workers(8, by_key)
)]
async fn place(order: &Order) -> HandlerOutcome {
tracing::info!(order.id, "accepted");
HandlerOutcome::ack()
}
fn app() -> RustStream {
RustStream::new(AppInfo::new("orders", "0.1.0"))
.with_broker(KafkaBroker::new(["localhost:9092"]), |b| {
b.include(place);
})
}Sourcepub fn config(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn config(self, key: impl Into<String>, value: impl Into<String>) -> Self
Raw librdkafka consumer property passthrough for anything not surfaced as a typed option, applied last (it wins over the typed options and the broker-wide config).
The exception is a property the subscription’s Commit mode owns
(enable.auto.offset.store, enable.auto.commit) under
Commit::Tracked or
Commit::Transactional: taking it back would leave the
committed position to librdkafka while every ack decided nothing, so the subscription
refuses to open instead. Commit::Auto owns neither and takes both.
Trait Implementations§
Source§impl Clone for KafkaTopic
impl Clone for KafkaTopic
Source§impl Debug for KafkaTopic
impl Debug for KafkaTopic
Source§impl IntoSource for KafkaTopic
impl IntoSource for KafkaTopic
Source§type Source = KafkaTopic
type Source = KafkaTopic
Source§fn into_source(self) -> Self
fn into_source(self) -> Self
Source§impl RedeliveryAddressed<ConnectedKafkaBroker> for KafkaTopic
impl RedeliveryAddressed<ConnectedKafkaBroker> for KafkaTopic
Source§fn redelivery_address(
&self,
_connected: &ConnectedKafkaBroker,
) -> impl Future<Output = Result<RedeliveryAddress, KafkaError>>
fn redelivery_address( &self, _connected: &ConnectedKafkaBroker, ) -> impl Future<Output = Result<RedeliveryAddress, KafkaError>>
The topic itself: a record produced to it reaches every group reading it, this subscription included.
Answered from the descriptor alone, so nothing is awaited.
Source§impl SubscriptionSource<ConnectedKafkaBroker> for KafkaTopic
impl SubscriptionSource<ConnectedKafkaBroker> for KafkaTopic
Source§type Subscriber = KafkaSubscriber
type Subscriber = KafkaSubscriber
Source§type Copies = AddressedCopies
type Copies = AddressedCopies
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 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 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
Auto Trait Implementations§
impl Freeze for KafkaTopic
impl RefUnwindSafe for KafkaTopic
impl Send for KafkaTopic
impl Sync for KafkaTopic
impl Unpin for KafkaTopic
impl UnsafeUnpin for KafkaTopic
impl UnwindSafe for KafkaTopic
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