#[doc(hidden)]
pub mod wit {
#![allow(missing_docs)]
use crate::wit_bindgen;
wit_bindgen::generate!({
runtime_path: "crate::wit_bindgen::rt",
world: "spin-sdk-mqtt",
path: "wit",
generate_all,
});
pub use spin::mqtt::mqtt;
}
pub struct Connection(wit::mqtt::Connection);
pub use wit::mqtt::{Error, Payload, Qos};
impl Connection {
pub async fn open(
address: impl AsRef<str>,
username: impl AsRef<str>,
password: impl AsRef<str>,
keep_alive_interval_in_secs: u64,
) -> Result<Self, Error> {
wit::mqtt::Connection::open(
address.as_ref().to_string(),
username.as_ref().to_string(),
password.as_ref().to_string(),
keep_alive_interval_in_secs,
)
.await
.map(Connection)
}
pub async fn publish(
&self,
topic: impl AsRef<str>,
payload: Vec<u8>,
qos: Qos,
) -> Result<(), Error> {
self.0
.publish(topic.as_ref().to_string(), payload, qos)
.await
}
}