pub struct MqttClient { /* private fields */ }Expand description
Async MQTT client.
Internally owns both the rumqttc::AsyncClient (for publish/subscribe) and
the rumqttc::EventLoop (which must be polled continuously to keep the
connection alive).
Implementations§
Source§impl MqttClient
impl MqttClient
Sourcepub fn new(config: MqttConfig) -> Result<(Self, EventLoop)>
pub fn new(config: MqttConfig) -> Result<(Self, EventLoop)>
Create a new client and connect to the broker described by config.
The returned EventLoop must be driven by calling MqttClient::run_event_loop
or by polling it manually in a dedicated task.
Sourcepub async fn publish_message(
&self,
topic: &str,
message: &Message,
) -> Result<()>
pub async fn publish_message( &self, topic: &str, message: &Message, ) -> Result<()>
Publish a serialised Message to the given topic.
Sourcepub async fn publish_json(
&self,
topic: &str,
payload: &impl Serialize,
) -> Result<()>
pub async fn publish_json( &self, topic: &str, payload: &impl Serialize, ) -> Result<()>
Publish a raw JSON payload to the given topic.
Sourcepub async fn publish_raw(&self, topic: &str, payload: Vec<u8>) -> Result<()>
pub async fn publish_raw(&self, topic: &str, payload: Vec<u8>) -> Result<()>
Publish raw bytes to the given topic.
Sourcepub async fn subscribe(&self, topic: &str) -> Result<()>
pub async fn subscribe(&self, topic: &str) -> Result<()>
Subscribe to a topic pattern (MQTT wildcards + and # supported).
Sourcepub async fn unsubscribe(&self, topic: &str) -> Result<()>
pub async fn unsubscribe(&self, topic: &str) -> Result<()>
Unsubscribe from a topic.
Auto Trait Implementations§
impl Freeze for MqttClient
impl RefUnwindSafe for MqttClient
impl Send for MqttClient
impl Sync for MqttClient
impl Unpin for MqttClient
impl UnwindSafe for MqttClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more