pub struct DeliveryTopic;Expand description
The key for MqttContext::topic.
It reads the topic borrowed through ctx.context(DeliveryTopic), and owned through the
Ctx<DeliveryTopic> extractor, which is also what fixes a handler’s context type to
MqttContext without a Context parameter.
§Examples
use std::error::Error;
use ruststream::testing::TestApp;
use ruststream_rumqttc::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Outgoing)]
struct Telemetry {
temperature: f64,
}
#[derive(Debug, PartialEq, Deserialize, Serialize, Outgoing)]
#[outgoing(name = "alerts")]
struct Alert {
topic: String,
}
#[subscriber(MqttFilter::new("devices/+/telemetry"))]
async fn watch(
telemetry: &Telemetry,
Ctx(topic): Ctx<DeliveryTopic>,
Out(alerts): Out<impl Publisher>,
) -> HandlerOutcome {
if telemetry.temperature <= 30.0 {
return HandlerOutcome::ack();
}
if alerts.message(&Alert { topic }).publish().await.is_err() {
return HandlerOutcome::retry();
}
HandlerOutcome::ack()
}
pub fn app() -> impl App {
RustStream::new(AppInfo::new("telemetry", "0.1.0")).with_broker(
MqttBroker::new("mqtt://localhost:1883", "telemetry-svc"),
|b| {
b.include(watch)
.out(DefaultSlot, Publish::default())
.out_retry(Publish::default())
.to("devices/retry/telemetry")
.build();
},
)
}
pub async fn an_alert_names_the_topic_not_the_filter() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
tb.broker::<MqttBroker>()
.message(&Telemetry { temperature: 31.5 })
.to("devices/dev42/telemetry")
.publish()
.await?;
tb.broker::<MqttBroker>()
.published::<Alert>("alerts")
.assert_called_once()
.with(&Alert { topic: "devices/dev42/telemetry".to_owned() });
tb.shutdown().await?;
Ok(())
}Trait Implementations§
Source§impl Clone for DeliveryTopic
impl Clone for DeliveryTopic
Source§impl ContextField for DeliveryTopic
impl ContextField for DeliveryTopic
Source§type Context = MqttContext
type Context = MqttContext
The per-delivery context type this key reads from.
Source§fn read(self, src: &MqttContext) -> String
fn read(self, src: &MqttContext) -> String
Reads this key’s field out of
src. Named apart from Field::get so a key
implementing both traits stays unambiguous to call.impl Copy for DeliveryTopic
Source§impl Debug for DeliveryTopic
impl Debug for DeliveryTopic
Source§impl Default for DeliveryTopic
impl Default for DeliveryTopic
impl Eq for DeliveryTopic
Source§impl Field<MqttContext> for DeliveryTopic
impl Field<MqttContext> for DeliveryTopic
Source§impl PartialEq for DeliveryTopic
impl PartialEq for DeliveryTopic
impl StructuralPartialEq for DeliveryTopic
Auto Trait Implementations§
impl Freeze for DeliveryTopic
impl RefUnwindSafe for DeliveryTopic
impl Send for DeliveryTopic
impl Sync for DeliveryTopic
impl Unpin for DeliveryTopic
impl UnsafeUnpin for DeliveryTopic
impl UnwindSafe for DeliveryTopic
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<K> CtxKey for Kwhere
K: ContextField,
impl<K> CtxKey for Kwhere
K: ContextField,
Source§type Value = <K as ContextField>::Value
type Value = <K as ContextField>::Value
The owned value the extractor binds.
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