Description

A MQTT broker client for D

Package Information

Version0.2.0-alpha.2 (2017-Feb-05)
Repositoryhttps://github.com/tchaloupka/vibe-mqtt
LicenseBSL-1.0
CopyrightCopyright © 2015, Tomáš Chaloupka
AuthorsTomáš Chaloupka
Registered byTomáš Chaloupka
Dependenciesnone

Installation

To use this package, put the following dependency into your project's dependencies section:

dub.json
dub.sdl

Readme

Build Status Dub downloads License Latest version

vibe-mqtt

MQTT broker client library written completely in D.

MQTT protocol version supported: 3.1.1

Depends on: vibe.d

Tested on:

Supported MQTT 3.1.1 features:

  • [x] QoS0, QoS1 and QoS2 messages handling
  • [x] Authentication
  • [x] Session state storage (currently in memory only - #20)
  • [x] Sending retain messages
  • [x] Async API (publish blocks if send queue is full)
  • [x] Data agnostic
  • [x] Message ordering
  • [x] KeepAlive mechanism support (PingReq/PingResp) (#11)
  • [ ] On subscribe topics validation (#17)
  • [ ] Last Will and Testament (LWT) (#21)
  • [ ] Delivery retry (#14)
  • [ ] Auto reconnect to broker (#15)
  • [ ] TLS/SSL (#16)

Pull Requests are welcome, don't be shy ;)

Usage

Example code can be found in the examples directory.

Publisher

Simple publisher which connects to the MQTT broker and periodically sends a message. Implicitly it connects to 127.0.0.1:1883

auto settings = Settings();
settings.clientId = "test publisher";

auto mqtt = new MqttClient(settings);
mqtt.connect();

auto publisher = runTask(() {
        while (mqtt.connected) {
            mqtt.publish("chat", "I'm still here!!!");
            sleep(2.seconds());
        }
    });

Subscriber

Simple subscriber which connects to the MQTT broker, subscribes to the topic and outputs each received message. Implicitly it connects to 127.0.0.1:1883

class Subscriber : MqttClient {
    this(Settings settings) {
        super(settings);
    }

    override void onPublish(Publish packet) {
        super.onPublish(packet);
        writeln("chat: ", cast(string)packet.payload);
    }

    override void onConnAck(ConnAck packet) {
        super.onConnAck(packet);
        this.subscribe(["chat"]);
    }
}

auto settings = Settings();
settings.clientId = "test subscriber";

auto mqtt = new Subscriber(settings);
mqtt.connect();

Available versions

0.2.0-alpha.2 0.2.0-alpha.1 0.1.8 0.1.7 0.1.6 0.1.5 0.1.4 0.1.3 0.1.2 0.1.1 0.1.0 ~master ~0.1.7_fixes