pub struct ToSourceTopic;Expand description
A PublishTransform sending each retry copy back to the topic its delivery arrived on.
A KafkaTopics subscription reads several topics, and a
KafkaPartitions reader reads part of one, so neither addresses its
own retry copies and every registration over them names where a copy goes. Naming one fixed
topic with .to(topic) sends an orders-eu record’s retry to that topic whatever it was;
this transform reads the record’s own topic out of the delivery instead, so a retry stays
where it belongs and the handler sees it arrive under the same name.
It writes no per-record setting, so it mounts over any Kafka publisher, and it takes the
destination, so it mounts where nothing else has declared one - a retry position with no
.to(topic).
The topic comes from KafkaContext, which reaches the position when the handler reads that
context (any Ctx<..> key of context::keys). A batch handler carries
KafkaBatchContext instead, which holds no per-record
topic, so a batch registration names its destination with .to(topic).
§Examples
use ruststream_rdkafka::prelude::*;
/// Reading the source topic is also what puts the Kafka context on this registration, which
/// is what the transform reads.
#[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)
.max_attempts(nonzero!(5u32))
.dead_letter("orders.dlq")
.out_retry(Publish::default())
.transform(ToSourceTopic);
})
}Trait Implementations§
Source§impl Clone for ToSourceTopic
impl Clone for ToSourceTopic
impl Copy for ToSourceTopic
Source§impl Debug for ToSourceTopic
impl Debug for ToSourceTopic
Source§impl Default for ToSourceTopic
impl Default for ToSourceTopic
impl Eq for ToSourceTopic
Source§impl PartialEq for ToSourceTopic
impl PartialEq for ToSourceTopic
Source§impl<Options> PublishTransform<ForReply<KafkaContext>, Options> for ToSourceTopic
impl<Options> PublishTransform<ForReply<KafkaContext>, Options> for ToSourceTopic
Source§fn apply(
&self,
out: &mut Outgoing<'_>,
_options: &mut Option<Options>,
cx: &PublishContext<'_, KafkaContext>,
)
fn apply( &self, out: &mut Outgoing<'_>, _options: &mut Option<Options>, cx: &PublishContext<'_, KafkaContext>, )
out in place before it is sent, reading the position’s view through cx and
resolving the broker’s per-message settings through options. Read moreimpl StructuralPartialEq for ToSourceTopic
Auto Trait Implementations§
impl Freeze for ToSourceTopic
impl RefUnwindSafe for ToSourceTopic
impl Send for ToSourceTopic
impl Sync for ToSourceTopic
impl Unpin for ToSourceTopic
impl UnsafeUnpin for ToSourceTopic
impl UnwindSafe for ToSourceTopic
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,
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.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