项目作者: tchaloupka

项目描述 :
MQTT client for D
高级语言: D
项目地址: git://github.com/tchaloupka/vibe-mqtt.git
创建时间: 2015-07-18T19:42:32Z
项目社区:https://github.com/tchaloupka/vibe-mqtt

开源协议:Boost Software License 1.0

下载


Actions Status
Dub downloads
License
Latest version

vibe-mqtt

MQTT broker client library written completely in D.

API documentation

MQTT protocol version supported: 3.1.1

Depends on: vibe.d

Tested on:

Supported MQTT 3.1.1 features:

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

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

  1. auto settings = Settings();
  2. settings.clientId = "test publisher";
  3. auto mqtt = new MqttClient(settings);
  4. mqtt.connect();
  5. auto publisher = runTask(() {
  6. while (mqtt.connected) {
  7. mqtt.publish("chat", "I'm still here!!!");
  8. sleep(2.seconds());
  9. }
  10. });

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

  1. auto settings = Settings();
  2. settings.clientId = "test subscriber";
  3. settings.onConnAck = (scope MqttClient ctx, in ConnAck packet)
  4. {
  5. ctx.subscribe(["chat"]);
  6. };
  7. settings.onPublish = (scope MqttClient ctx, in Publish packet)
  8. {
  9. writeln("chat: ", cast(string)packet.payload);
  10. };
  11. auto mqtt = new MqttClient(settings);
  12. mqtt.connect();