pub struct PulsarPublishOptions {
pub partition_key: Option<String>,
}Expand description
What one Pulsar publish differs from the next in.
Every field is optional: a message carries what its call site named with a step of
PulsarPublishSteps, and nothing else. The PulsarPublish policy fixes no key of its
own, so a publish that names no step goes unkeyed.
§Examples
A test reads them back off the slot the handler published through:
use std::error::Error;
use ruststream::testing::TestApp;
use ruststream_pulsar::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Outgoing, Serialize)]
struct Order {
id: u64,
}
#[derive(Outgoing, Serialize)]
struct Receipt {
id: u64,
}
#[derive(OutSlot)]
#[publishes(Receipt)]
struct Ledger;
#[subscriber(PulsarSubscription::new("orders", "workers"))]
async fn record(
order: &Order,
Out(ledger): Out<impl Publisher<Options = PulsarPublishOptions>, Ledger>,
) -> HandlerOutcome {
let sent = ledger
.message(&Receipt { id: order.id })
.to("receipts")
.partition_key(format!("user-{}", order.id))
.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(PulsarBroker::new("pulsar://localhost:6650"), |b| {
b.include(record).out(Ledger, Publish).build();
})
}
pub async fn a_receipt_is_keyed_by_its_user() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
tb.broker::<PulsarBroker>()
.message(&Order { id: 7 })
.to("orders")
.publish()
.await?;
tb.out::<Ledger>()
.assert_called_once()
.with_options(&PulsarPublishOptions {
partition_key: Some("user-7".to_owned()),
});
tb.shutdown().await?;
Ok(())
}Fields§
§partition_key: Option<String>The message’s partition key: keyed routing places the message by it and KeyShared
subscriptions order by it.
None leaves the key to the partition-key header, the portable spelling of the same
value; with neither, the message is unkeyed.
Trait Implementations§
Source§impl Clone for PulsarPublishOptions
impl Clone for PulsarPublishOptions
Source§impl Debug for PulsarPublishOptions
impl Debug for PulsarPublishOptions
Source§impl Default for PulsarPublishOptions
impl Default for PulsarPublishOptions
impl Eq for PulsarPublishOptions
Source§impl PartialEq for PulsarPublishOptions
impl PartialEq for PulsarPublishOptions
impl StructuralPartialEq for PulsarPublishOptions
Auto Trait Implementations§
impl Freeze for PulsarPublishOptions
impl RefUnwindSafe for PulsarPublishOptions
impl Send for PulsarPublishOptions
impl Sync for PulsarPublishOptions
impl Unpin for PulsarPublishOptions
impl UnsafeUnpin for PulsarPublishOptions
impl UnwindSafe for PulsarPublishOptions
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
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<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.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