|
33 | 33 | //! ```bash |
34 | 34 | //! mosquitto_pub -h localhost -t 'commands/temp/indoor' -m '{"action":"read","sensor_id":"indoor-001"}' |
35 | 35 | //! ``` |
| 36 | +//! |
| 37 | +//! ## TLS (mqtts://) |
| 38 | +//! |
| 39 | +//! The broker URL is read from `MQTT_BROKER_URL` (defaults to |
| 40 | +//! `mqtt://localhost:1883`). To exercise the `mqtts://` TLS transport against |
| 41 | +//! a local mosquitto broker configured with a self-signed CA: |
| 42 | +//! |
| 43 | +//! ```bash |
| 44 | +//! SSL_CERT_FILE=/path/to/ca.crt \ |
| 45 | +//! MQTT_BROKER_URL=mqtts://localhost:8883 \ |
| 46 | +//! cargo run -p tokio-mqtt-connector-demo --features tokio-runtime |
| 47 | +//! ``` |
| 48 | +//! |
| 49 | +//! `SSL_CERT_FILE` is honored by the native-tls/OpenSSL backend on Linux to |
| 50 | +//! extend the trusted roots without touching the system store — required |
| 51 | +//! because a self-signed broker cert won't otherwise validate. |
36 | 52 |
|
37 | 53 | use aimdb_core::buffer::BufferCfg; |
38 | 54 | use aimdb_core::{AimDbBuilder, DbResult, Producer, RecordKey, RuntimeContext}; |
@@ -130,12 +146,16 @@ async fn main() -> DbResult<()> { |
130 | 146 |
|
131 | 147 | let runtime = Arc::new(TokioAdapter::new()?); |
132 | 148 |
|
| 149 | + let broker_url = std::env::var("MQTT_BROKER_URL") |
| 150 | + .unwrap_or_else(|_| "mqtt://localhost:1883".to_string()); |
| 151 | + |
133 | 152 | println!("MQTT Connector Demo"); |
134 | 153 | println!("==================="); |
| 154 | + println!("Broker: {broker_url}"); |
135 | 155 | println!(); |
136 | 156 |
|
137 | 157 | let mut builder = AimDbBuilder::new().runtime(runtime).with_connector( |
138 | | - aimdb_mqtt_connector::MqttConnector::new("mqtt://localhost:1883") |
| 158 | + aimdb_mqtt_connector::MqttConnector::new(broker_url) |
139 | 159 | .with_client_id("tokio-demo-multi-sensor"), |
140 | 160 | ); |
141 | 161 |
|
|
0 commit comments