#mqtt-client #stream #tls #tcp #protocols #mqttc #mqtt3

netopt

Provides options to work with tcp or ssl streams and has a choice in between

4 releases

Uses old Rust 2015

0.1.3 Jun 2, 2016
0.1.2 Apr 18, 2016
0.1.1 Apr 17, 2016
0.1.0 Mar 21, 2016

#32 in #mqtt-client

Download history 42/week @ 2024-03-30 26/week @ 2024-04-06 32/week @ 2024-04-13 32/week @ 2024-04-20 28/week @ 2024-04-27 29/week @ 2024-05-04 32/week @ 2024-05-11 39/week @ 2024-05-18 28/week @ 2024-05-25 27/week @ 2024-06-01 16/week @ 2024-06-08 28/week @ 2024-06-15 31/week @ 2024-06-22 5/week @ 2024-06-29 4/week @ 2024-07-06 10/week @ 2024-07-13

54 downloads per month
Used in 2 crates

MIT license

62KB
2K SLoC

RustMQ

Build Status

This repository is the bundle of crates devoted to the MQTT protocol.

Crates

  • mqtt3 - MQTT protocol reader/writer Crates.io
  • netopt - TCP/SSL connection Crates.io
  • mqttc - Rust MQTT client Crates.io

Binaries

  • mqttc - Console MQTT client

Client

The client has the following functionality:

  • QoS 0, QoS 1, QoS 2 publish/subscribe
  • Last Will message
  • Auto-Ping
  • Auto-Reconnect
  • SSL supported (include TLS v1.1, TLS v1.2)
  • Modular: mqtt3, netopt
  • Logging

Connect

let netopt = NetworkOptions::new();
let mut opts = ClientOptions::new();
opts.set_reconnect(ReconnectMethod::ReconnectAfter(Duration::from_secs(1)));
let mut client = opts.connect("127.0.0.1:1883", netopt).expect("Can't connect to server");

Publish

client.publish("a/b/c", "hello", PubOpt.at_least_once()).unwrap();
while (client.await().unwrap().is_some()) {};

Subscribe

client.subscribe("a/b/c").unwrap();
loop {
    match client.await().unwrap() {
        Some(message) => {
            println!("{:?}", message);
        },
        None => {}
    }
}

Command line interface

mqtt-cli

MQTT Client installation:

git clone https://github.com/inre/rust-mq.git
cd rust-mq
make && make install

Subscribe to all topics:

mqttc sub

Or try,

mqttc sub -a test.mosquitto.org
mqttc sub -a iot.eclipse.org
mqttc sub -a test.mosca.io
mqttc sub -a broker.hivemq.com

Publish to the topic:

mqttc pub -t a/b/c -m "hello"

Server

Maybe in future

Dependencies

~0.2–1.8MB
~39K SLoC