#[non_exhaustive]pub struct MqttContext { /* private fields */ }Expand description
The per-delivery context of this broker.
Read a field with a key rather than by field access: ctx.context(DeliveryTopic) in a handler
body, cx.context(DeliveryTopic) in a publish transform on the reply or the retry position.
§Examples
use ruststream_rumqttc::prelude::*;
use serde::Deserialize;
#[derive(Deserialize)]
struct Telemetry {
temperature: f64,
}
#[subscriber(MqttFilter::new("devices/+/telemetry"))]
async fn record(telemetry: &Telemetry, ctx: &mut Context<'_, MqttContext>) -> HandlerOutcome {
let device = ctx.context(DeliveryTopic).split('/').nth(1).unwrap_or_default();
tracing::info!(device, telemetry.temperature, "reading recorded");
HandlerOutcome::ack()
}
#[ruststream::app]
fn app() -> impl App {
RustStream::new(AppInfo::new("telemetry", "0.1.0")).with_broker(
MqttBroker::new("mqtt://localhost:1883", "telemetry-svc"),
|b| {
b.include(record)
.out_retry(Publish::default())
.to("devices/retry/telemetry");
},
)
}Implementations§
Trait Implementations§
Source§impl BuildContext<MqttMessage> for MqttContext
impl BuildContext<MqttMessage> for MqttContext
Source§fn build(msg: &MqttMessage) -> Self
fn build(msg: &MqttMessage) -> Self
Builds the context value by reading fields out of
msg.Source§impl Clone for MqttContext
impl Clone for MqttContext
Source§impl Debug for MqttContext
impl Debug for MqttContext
impl Eq for MqttContext
Source§impl Field<MqttContext> for DeliveryTopic
impl Field<MqttContext> for DeliveryTopic
Source§impl PartialEq for MqttContext
impl PartialEq for MqttContext
impl StructuralPartialEq for MqttContext
Auto Trait Implementations§
impl Freeze for MqttContext
impl RefUnwindSafe for MqttContext
impl Send for MqttContext
impl Sync for MqttContext
impl Unpin for MqttContext
impl UnsafeUnpin for MqttContext
impl UnwindSafe for MqttContext
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.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