PHPMQTT v1.3.2 版本发布,优化 MQTT5 相关支持

栏目: 软件资讯 · 发布时间: 5年前

内容简介:添加 toArray 方法 在上个版本中为 getContents 方法增加了一个 getArray 参数来用于客户端回复对端 ACK,此版本中增加了 toArray 方法进行获取: use Simps\MQTT\Message; use Simps\MQTT\Protocol\ProtocolI...
  1. 添加 toArray 方法

在上个版本中为 getContents 方法增加了一个 getArray 参数来用于客户端回复对端 ACK,此版本中增加了 toArray 方法进行获取:

use Simps\MQTT\Message;
use Simps\MQTT\Protocol\ProtocolInterface;

$message = new Message\Publish();
$message->setProtocolLevel(ProtocolInterface::MQTT_PROTOCOL_LEVEL_5_0)
    ->setTopic('simps/mqtt/message')
    ->setQos(ProtocolInterface::MQTT_QOS_1)
    ->setDup(ProtocolInterface::MQTT_DUP_0)
    ->setRetain(ProtocolInterface::MQTT_RETAIN_0)
    ->setMessage('this is content')
    ->setMessageId(1)
    ->setProperties(['message_expiry_interval' => 100]);

$array1 = $message->getContents(true);
$array2 = $message->toArray();
assert($array1 === $array2);

两者的结果相同。

  1. 优化 getProtocolLevel

MQTT5 协议中增加了一个 Properties 属性,而 MQTT3.x 中是没有的,之前的版本如果是 MQTT5 协议的话需要手动调用setProtocolLevel来设置协议等级,此版本中就增加优化:判断是否设置了Properties 属性,如果设置了但协议等级不是 MQTT5 则自动设置为 MQTT5

  • Message
use Simps\MQTT\Message;
use Simps\MQTT\Protocol\ProtocolInterface;

$message = new Message\Publish();
$message->setTopic('simps/mqtt/message')
    ->setQos(ProtocolInterface::MQTT_QOS_1)
    ->setDup(ProtocolInterface::MQTT_DUP_0)
    ->setRetain(ProtocolInterface::MQTT_RETAIN_0)
    ->setMessage('this is content')
    ->setMessageId(1);

assert($message->isMQTT5() === false);
assert($message->getProtocolLevel() === ProtocolInterface::MQTT_PROTOCOL_LEVEL_3_1_1);

$message->setProperties(['message_expiry_interval' => 100]);
assert($message->isMQTT5() === true);
assert($message->getProtocolLevel() === ProtocolInterface::MQTT_PROTOCOL_LEVEL_5_0);

$message->setProtocolLevel(ProtocolInterface::MQTT_PROTOCOL_LEVEL_3_1);
assert($message->isMQTT5() === true);
assert($message->getProtocolLevel() === ProtocolInterface::MQTT_PROTOCOL_LEVEL_5_0);
  • Config
use Simps\MQTT\Client;
use Simps\MQTT\Config\ClientConfig;
use Simps\MQTT\Protocol\ProtocolInterface;

$config = new ClientConfig();
$config->setClientId(Client::genClientID())
    ->setKeepAlive(10)
    ->setDelay(3000)
    ->setMaxAttempts(5)
    ->setProperties([
        'session_expiry_interval' => 100,
    ])
    ->setSwooleConfig([
        'open_mqtt_protocol' => true,
        'package_max_length' => 2 * 1024 * 1024,
    ]);

assert($config->isMQTT5() === true);
assert($config->getProtocolLevel() === ProtocolInterface::MQTT_PROTOCOL_LEVEL_5_0);

更新日志

增强

  • 添加 toArray 方法 (b3fd28a)
  • 更新属性默认值 (9c63510)
  • 添加遗嘱消息 Message 类 (#45)
  • 添加 Auth Message 类 (36f6a9d)
  • 增加 DUP、SESSION_PRESENT 和 RETAIN 的常量 (fe5c418)
  • 优化 getProtocolLevel (a329202)
  • 增加 isMQTT5 测试和使用常量代替硬编码(b9d4365)

修复

  • 修正 ReasonCode 中错字 (481994f5)

关于 PHPMQTT

  • 适用于 PHP 的 MQTT 协议解析和协程客户端
  • 支持 MQTT 协议 3.1、3.1.1 和 5.0 版本,支持 QoS 0、QoS 1、QoS 2
  • 首个支持 MQTT v5.0 协议的 PHP library

文档:https://mqtt.simps.io
GitHub:https://github.com/simps/mqtt
Gitee:https://gitee.com/phpiot/mqtt

支持记得点个 Star~


以上所述就是小编给大家介绍的《PHPMQTT v1.3.2 版本发布,优化 MQTT5 相关支持》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Introduction to Computer Science Using Python

Introduction to Computer Science Using Python

Dierbach, Charles / 2012-12 / $ 133.62

Introduction to Computer Science Using Python: A Computational Problem-Solving Focus introduces students to programming and computational problem-solving via a back-to-basics, step-by-step, objects-la......一起来看看 《Introduction to Computer Science Using Python》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具