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

添加 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);

两者的结果相同。优化 getProtocolLevel

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

支持记得点个 Star~

1460000039103727

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值