Hello All,
Significant improvements were added to the Paho Rust client over the
holiday break. The library now supports Rust Futures and Streams.
This allows an MQTT client to be fully integrated into an
application using Futures for other asynchronous I/O, such as for
data collection, file manipulation, or databases.
Futures allow asynchronous operations to work as simply as blocking
calls, while allowing threads to be shared between operations.
Chaining futures together lets us write concise code with full error
handling, such as this snippet which opens a client connection,
waits for it to complete, publishes a message, and then closes the
connection:
cli.connect(None)
.and_then(|_| {
let msg = mqtt::Message::new("test", "Hello futures
world!", 1);
cli.publish(msg)
})
.and_then(|_| cli.disconnect(None))
.wait().unwrap_or_else(|err| {
println!("Error: {}", err);
});
This is mostly compatible with the existing asynchronous API which
uses "Token" objects. Now the Tokens simply implement the Futures
trait.
The implementation is up on GitHub
(https://github.com/eclipse/paho.mqtt.rust). A release should be
coming shortly. This is the last major feature for the current
version of the library. Next, we'll move on to MQTT v5 support.
Frank
|