pub struct PubSubPublishOptions {
pub ordering_key: Option<String>,
}Expand description
The settings one Pub/Sub message may differ from the next by.
Pub/Sub gives a message exactly one such field, its ordering key, so that is the whole type.
The field is optional, because a publish carries only what its call site adjusted: what a call
leaves unset keeps what the PubSubPublish policy fixed at the mount site.
A handler body that names the ordering_key step bounds its
slot on this type, and a test reads the value back with
tb.out::<Marker>().with_options(..).
§Examples
use std::error::Error;
use ruststream::testing::TestApp;
use ruststream_gcp_pubsub::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Outgoing)]
struct Order {
id: u64,
}
#[subscriber("orders-workers")]
async fn confirm(
order: &Order,
Out(out): Out<impl Publisher<Options = PubSubPublishOptions>>,
) -> HandlerOutcome {
let sent = out
.message(order)
.to("confirmations")
.ordering_key(format!("order-{}", order.id))
.publish()
.await;
if sent.is_err() {
return HandlerOutcome::retry();
}
HandlerOutcome::ack()
}
/// The app `main` runs, and the one the test hands the harness.
pub fn app() -> impl App {
RustStream::new(AppInfo::new("orders", "0.1.0"))
.with_broker(PubSubBroker::new("my-project"), |b| {
b.include(confirm).out(DefaultSlot, Publish::default()).build();
})
}
pub async fn each_confirmation_carries_its_orders_key() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
// A subscription the service only names is attached to the topic of its own name.
tb.broker::<PubSubBroker>()
.message(&Order { id: 42 })
.to("orders-workers")
.publish()
.await?;
tb.settle().await?;
tb.out::<DefaultSlot>()
.assert_called(1)
.with_options(&PubSubPublishOptions {
ordering_key: Some("order-42".to_owned()),
});
tb.shutdown().await?;
Ok(())
}Fields§
§ordering_key: Option<String>The message’s ordering key. Messages sharing a key reach one subscriber in publish
order, on a subscription that enables message ordering; None leaves the publish
unordered unless the policy fixed a key.
Trait Implementations§
Source§impl Clone for PubSubPublishOptions
impl Clone for PubSubPublishOptions
Source§impl Debug for PubSubPublishOptions
impl Debug for PubSubPublishOptions
Source§impl Default for PubSubPublishOptions
impl Default for PubSubPublishOptions
impl Eq for PubSubPublishOptions
Source§impl PartialEq for PubSubPublishOptions
impl PartialEq for PubSubPublishOptions
impl StructuralPartialEq for PubSubPublishOptions
Auto Trait Implementations§
impl Freeze for PubSubPublishOptions
impl RefUnwindSafe for PubSubPublishOptions
impl Send for PubSubPublishOptions
impl Sync for PubSubPublishOptions
impl Unpin for PubSubPublishOptions
impl UnsafeUnpin for PubSubPublishOptions
impl UnwindSafe for PubSubPublishOptions
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§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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request