- 增加 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 则主动设置为 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~