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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
/*! This is a package for [CERK](https://github.com/ce-rust/cerk). CERK is an open source [CloudEvents](https://github.com/cloudevents/spec) Router written in Rust with a MicroKernel architecture. # Introduction CERK lets you route your [CloudEvents](https://github.com/cloudevents/spec) between different different ports. Ports are transport layer bindings over which CloudEvents can be exchanged. It is built with modularity and portability in mind. # Components CERK comes with a couple of prefabricated components, but implementing custom components is easy. A good overview is provided on [GitHub](https://github.com/ce-rust/cerk/). # This Component: MQTT Port This port publishes and/or subscribe CloudEvents to/from an MQTT v3.1 topic. The port is implemented with a [Eclipse Paho MQTT Rust Client](https://github.com/eclipse/paho.mqtt.rust) and sends and receives messages according to the [MQTT Protocol Binding for CloudEvents v1.0](https://github.com/cloudevents/spec/blob/v1.0/mqtt-protocol-binding.md) specification # Configurations The configurations should be of type `cerk::kernel::Config::HashMap` and have at least the entires: ## Required Fields ## host The value has to by of type `Config::String` and contain a host name with protocol and port. E.g. `Config::String(String::from("tcp://mqtt-broker:1883"))` ## Optional Fields ### send_topic The value has to by of type `Config::String` and contain the MQTT topic name where the message will be sent to. E.g. `Config::String(String::from("test"))` The following configurations are optional. ### persistence The value has to by of type `Config::U8` and contain one of the following values. The values are defined according to the Eclipse Paho MQTT Rust Client PersistenceType. * 0: File (default) - Data and messages are persisted to a local file (default) * 1: None - No persistence is used. E.g. `Config::U8(0)` ### send_qos The [quality of service](http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718099) for message delivery. The quality of service is only for the MQTT broker and does not change any behavior of the router or the port. The router only supports best effort at the moment. * 0: At most once delivery (default) * 1: At least once delivery * 2: Exactly once delivery E.g. `Config::U8(0)` ## subscribe_topics The value has to by of type `Config::Vec([Config::String])` and must have the same length as `subscribe_qos`. The values in the vector contain the MQTT topic wich the router should subscribe to. If multiple topics are subscribed in the same MQTT port, there is no possibility at the moment to know let the router or the output port know from which topic the event was received. ## subscribe_qos The value has to by of type `Config::Vec([Config::U8])` and must have the same length as `subscribe_topics`. The [quality of service](http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718099) for the topic subscription. The quality of service is only for the MQTT broker and does not change any behavior of the router or the port. The router only supports best effort at the moment. * 0: At most once delivery * 1: At least once delivery * 2: Exactly once delivery ## Configuration Examples ### Minimal Configuration to send events This configuration will connect to the broker but will not send or receive any events. ``` use std::collections::HashMap; use cerk::kernel::Config; let map: HashMap<String, Config> = [ ("host".to_string(), Config::String("tcp://mqtt-broker:1883".to_string())), ] .iter() .cloned() .collect(); let config = Config::HashMap(map); ``` ### Full Configuration for sending events ``` use std::collections::HashMap; use cerk::kernel::Config; let map: HashMap<String, Config> = [ ("host".to_string(), Config::String("tcp://mqtt-broker:1883".to_string())), ("persistence".to_string(), Config::U8(0)), ("send_topic".to_string(), Config::String("test".to_string())), ("send_qos".to_string(), Config::U8(2)), ] .iter() .cloned() .collect(); let config = Config::HashMap(map); ``` ### Full Configuration for recieve events ``` use std::collections::HashMap; use cerk::kernel::Config; let map: HashMap<String, Config> = [ ("host".to_string(), Config::String("tcp://mqtt-broker:1883".to_string())), ("persistence".to_string(), Config::U8(0)), ( "subscribe_topics".to_string(), Config::Vec(vec![Config::String("test".to_string())]), ), ( "subscribe_qos".to_string(), Config::Vec(vec![Config::U8(2)]), ), ] .iter() .cloned() .collect(); let config = Config::HashMap(map); ``` ### Full Configuration for receiving events ``` use std::collections::HashMap; use cerk::kernel::Config; let map: HashMap<String, Config> = [ ("host".to_string(), Config::String("tcp://mqtt-broker:1883".to_string())), ("persistence".to_string(), Config::U8(0)), ("send_topic".to_string(), Config::String("test".to_string())), ("send_qos".to_string(), Config::U8(2)), ( "subscribe_topics".to_string(), Config::Vec(vec![Config::String("test".to_string())]), ), ( "subscribe_qos".to_string(), Config::Vec(vec![Config::U8(2)]), ), ] .iter() .cloned() .collect(); let config = Config::HashMap(map); ``` # Examples * [Generator to MQTT](https://github.com/ce-rust/cerk/tree/master/examples/src/mqtt/) # Limitations * **reliability** this port does not support any `DeliveryGuarantee` other then `Unspecified` and so does never send a `OutgoingCloudEventProcessed` or `IncomingCloudEventProcessed` messages */ #![deny(missing_docs)] #[macro_use] extern crate log; mod port_mqtt; pub use self::port_mqtt::{port_mqtt_start, PORT_MQTT};