gemqtt/publisher
Module for publishing messages to an MQTT server.
Example usage:
let msg_payload = bit_array.from_string("test payload")
let assert Ok(_) =
publisher.new(client, "my/topic")
|> publisher.set_qos(gemqtt.AtLeastOnce)
|> publisher.publish(msg_payload)
Types
pub type PublishOption {
Retain(Bool)
Qos(gemqtt.Qos)
}
Constructors
-
Retain(Bool)
-
Qos(gemqtt.Qos)
Publisher holds the configuration for publishing to a particular topic.
Create it with the new
function.
pub type Publisher {
Publisher(
client: Client,
topic: String,
options: List(PublishOption),
properties: Properties,
)
}
Constructors
-
Publisher( client: Client, topic: String, options: List(PublishOption), properties: Properties, )
Functions
pub fn new(client: Client, topic: String) -> Publisher
Creates a new publisher for the specified topic.
pub fn publish(
publisher: Publisher,
payload: BitArray,
) -> Result(Option(Int), Error)
Sends a PUBLISH packet to the server.
Upon success, will returns Ok(Some(packet ID))
if QoS is AtLeastOnce
or
ExactlyOnce
, otherwise Ok(None)
.
pub fn set_qos(publisher: Publisher, qos: Qos) -> Publisher
Sets the QoS level for published messages; defaults to AtMostOnce
.
pub fn set_retain(
publisher: Publisher,
retain: Bool,
) -> Publisher
Indicates to the server whether the most recently published message should be retained for future subscribers as a last known good message on this topic. Defaults to false.