1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//! The imports a routes file on MQTT writes every time, in one glob.
//!
//! Carries the framework's own prelude plus this crate's surface: the broker, the two
//! subscription descriptors and their quality of service, the publish policy as [`Publish`], the
//! per-message publish steps, and the per-delivery context with its key.
//!
//! A handler file usually needs none of it: a body binds its injected publisher with a capability
//! trait and names no broker type, so it imports the framework's prelude alone. This glob is the
//! mount site's, and importing it is the statement of which broker the routes run on. The one
//! exception is a body that adjusts a per-message setting: it names [`MqttPublishOptions`] in its
//! slot bound and takes a step from [`MqttPublishSteps`], both of which arrive here.
//!
//! A file that mixes two brokers imports the prefixed [`MqttPublish`](crate::MqttPublish) from
//! the crate root instead.
//!
//! # Examples
//!
//! ```
//! # mod demo {
//! use ruststream_rumqttc::prelude::*;
//! use serde::{Deserialize, Serialize};
//!
//! #[derive(Deserialize)]
//! struct Telemetry {
//! device: String,
//! temperature: f64,
//! }
//!
//! #[derive(Serialize, Outgoing)]
//! #[outgoing(name = "alerts")]
//! struct Alert {
//! device: String,
//! }
//!
//! #[subscriber(MqttFilter::new("devices/+/telemetry").qos(Qos::AtLeastOnce).shared("workers"))]
//! async fn check(telemetry: &Telemetry, Out(alerts): Out<impl Publisher>) -> HandlerOutcome {
//! if telemetry.temperature <= 30.0 {
//! return HandlerOutcome::ack();
//! }
//! let alert = Alert { device: telemetry.device.clone() };
//! if alerts.message(&alert).publish().await.is_err() {
//! return HandlerOutcome::retry();
//! }
//! 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(check)
//! .out(DefaultSlot, Publish::default().qos(Qos::ExactlyOnce))
//! .out_retry(Publish::default())
//! .to("devices/retry/telemetry")
//! .build();
//! },
//! )
//! }
//! # }
//! # fn main() {}
//! ```
// Importing this prelude is itself a service's statement of which broker it runs on, which is why
// the core glob rides along here instead of being left to each service file.
pub use *;
// Policies are re-exported under their broker-agnostic concept name; keep the alias when adding
// one. The name is this glob's to give: a handler bounds its slot with a capability trait through
// the framework's prelude, and never sees this one.
pub use crate::;
// Capability manifest deliberately empty. Of the framework's optional capabilities MQTT
// implements only `BatchSubscriber` (see the crate overview), and the manifest is for the traits a
// handler bounds its slot with: a batch handler names a size at its mount site and never that
// trait. Add one here when a capability a body binds lands.
// Deliberately absent, do not add:
// - `MqttMessage`, `MqttSubscriber`, `MqttPublisher`, `ConnectedMqttBroker`: a service reaches
// these through the framework's own surfaces.
// - `MqttError`: named where it is handled.