MQTT Rust Client

This Rust client provides an interface which is intended to mirror the Paho Java and C++ API's as closely as possible. It requires the Paho MQTT C client library.

Note that the Rust client is still in early, pre-release development, and is due for a formal release in early 2018.

Features

Source

Source is available from the GitHub repository.

Download

When the project is formally released, it will be made availble on the Rust crates.io site.

Building from source

The project uses the standard Rust project/package manager, Cargo. Simply clone the repository and run cargo build

See the GitHub page for additional requirements and build instructions.

Documentation

Reference documentation is online.

Getting Started

There are a number of small sample applications in the examples directory of the repository. These can all be built with the command: cargo build --examples

Here is a simple example of publishing with the Rust asynchronous API:

extern crate paho_mqtt as mqtt;

use std::process;

fn main() {
    // Create a client & define connect options
    let cli = mqtt::AsyncClient::new("tcp://localhost:1883").unwrap_or_else(|err| {
        println!("Error creating the client: {}", err);
        process::exit(1);
    });

    let conn_opts = mqtt::ConnectOptions::new();

    // Connect and wait for it to complete or fail
    if let Err(e) = cli.connect(conn_opts).wait() {
        println!("Unable to connect: {:?}", e);
        process::exit(1);
    }

    // Create a message and publish it
    println!("Publishing a message on the 'test' topic");
    let msg = mqtt::Message::new("test", "Hello world!", 0);
    let tok = cli.publish(msg);

    if let Err(e) = tok.wait() {
        println!("Error sending message: {:?}", e);
    }

    // Disconnect from the broker
    let tok = cli.disconnect(None);
    tok.wait().unwrap();
}