pub struct KafkaOptions { /* private fields */ }Expand description
What one Kafka record carries beyond its topic, payload and headers.
A publish builder writes these through the steps of KafkaPublishSteps; nothing else needs
to name the type, except an assertion reading back what a publish carried
(tb.out::<Marker>().with_options(&KafkaOptions::default().partition(3))).
The record key is deliberately absent: it is the core’s Partitioned
contract, carried by the PARTITION_KEY_HEADER header so that
broker-agnostic code can set it, and Kafka maps it onto the native key.
§Examples
A test reading back the partition a handler’s publish asked for:
use std::error::Error;
use ruststream::testing::TestApp;
use ruststream_rdkafka::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Outgoing)]
struct Order {
id: u64,
}
#[derive(Serialize, Outgoing)]
#[outgoing(name = "audit")]
struct Audit {
id: u64,
}
#[derive(OutSlot)]
#[publishes(Audit)]
struct Journal;
#[subscriber("orders")]
async fn record(
order: &Order,
Out(journal): Out<impl Publisher<Options = KafkaOptions>, Journal>,
) -> HandlerOutcome {
let sent = journal.message(&Audit { id: order.id }).partition(3).publish().await;
if sent.is_err() {
return HandlerOutcome::retry();
}
HandlerOutcome::ack()
}
pub fn app() -> RustStream {
RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(
KafkaBroker::new(["kafka:9092"]).default_group("orders-svc"),
|b| {
b.include(record).out(Journal, Publish::default()).build();
},
)
}
pub async fn audits_go_to_partition_three() -> Result<(), Box<dyn Error + Send + Sync>> {
let tb = TestApp::start(app()).await?;
tb.broker::<KafkaBroker>()
.message(&Order { id: 7 })
.to("orders")
.publish()
.await?;
tb.out::<Journal>()
.assert_called(1)
.with_options(&KafkaOptions::default().partition(3));
tb.shutdown().await?;
Ok(())
}Implementations§
Source§impl KafkaOptions
impl KafkaOptions
Trait Implementations§
Source§impl Clone for KafkaOptions
impl Clone for KafkaOptions
impl Copy for KafkaOptions
Source§impl Debug for KafkaOptions
impl Debug for KafkaOptions
Source§impl Default for KafkaOptions
impl Default for KafkaOptions
impl Eq for KafkaOptions
Source§impl PartialEq for KafkaOptions
impl PartialEq for KafkaOptions
Source§impl<K: ContextKind> PublishTransform<K, KafkaOptions> for RoundRobin
impl<K: ContextKind> PublishTransform<K, KafkaOptions> for RoundRobin
impl StructuralPartialEq for KafkaOptions
Auto Trait Implementations§
impl Freeze for KafkaOptions
impl RefUnwindSafe for KafkaOptions
impl Send for KafkaOptions
impl Sync for KafkaOptions
impl Unpin for KafkaOptions
impl UnsafeUnpin for KafkaOptions
impl UnwindSafe for KafkaOptions
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
Mutably borrows from an owned value. Read more
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
Compare self to
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> ⓘ
Converts
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> ⓘ
Converts
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