PHPMQTT v1.2.1 版本发布,MQTT 协议解析 & 协程客户端

v1.2 版本主要修改了 Client 的构造函数参数和 Protocol 的命名空间,以及优化重连逻辑。

Protocol

新增一层Protocol,使用V3V5来区分 MQTT 协议等级。

同时将Simps\MQTT\Types也移动到了Protocol下,修改为Simps\MQTT\Protocol\Types

1.1

Simps\MQTT\Protocol::pack(array $array)
Simps\MQTT\ProtocolV5::pack(array $array)
Simps\MQTT\ProtocolInterface::MQTT_PROTOCOL_LEVEL_3_1;

Simps\MQTT\Types::CONNECT;

1.2

Simps\MQTT\Protocol\V3::pack(array $array)
Simps\MQTT\Protocol\V5::pack(array $array)
Simps\MQTT\Protocol\ProtocolInterface::MQTT_PROTOCOL_LEVEL_3_1;

Simps\MQTT\Protocol\Types::CONNECT;

Client

Client 之前是直接传递数组参数的,现在改为对象的方式。

1.1

use Simps\MQTT\Client;

$config = [
    'host' => '127.0.0.1',
    'port' => 1883,
    'user_name' => '',
    'password' => '',
    'client_id' => Client::genClientID(),
    'keep_alive' => 10,
];
$swooleConfig = [
    'open_mqtt_protocol' => true,
    'package_max_length' => 2 * 1024 * 1024,
    'connect_timeout' => 1.0,
    'write_timeout' => 3.0,
    'read_timeout' => 0.5,
];
$client = new Client($config, $swooleConfig);

1.2

use Simps\MQTT\Client;
use Simps\MQTT\Config\ClientConfig;

$config = new ClientConfig();
$config->setUserName('')
    ->setPassword('')
    ->setClientId(Client::genClientID())
    ->setKeepAlive(10);

$swooleConfig = [
    'open_mqtt_protocol' => true,
    'package_max_length' => 2 * 1024 * 1024,
    'connect_timeout' => 1.0,
    'write_timeout' => 3.0,
    'read_timeout' => 0.5,
];
$config->setSwooleConfig($swooleConfig);
$client = new Client('127.0.0.1', 1883, $config);

// 也可以这样设置
$config = new ClientConfig([
    'userName' => '',
    'password' => '',
    'clientId' => '',
    'keepAlive' => 10,
    'protocolName' => 'MQTT',
    'protocolLevel' => 4,
    'properties' => [],
    'delay' => 3000, // 3s
    'swooleConfig' => []
]);
$client = new Client('127.0.0.1', 1883, $config);

更新日志

向下不兼容

  • 更新命名空间 (2204df6) (28f8abe)

移除

  • 不支持 PHP 7.0 (3dc5bcd)

增强

  • 为所有的常量添加可见性标识符 (0176469)
  • 新增 ClientConfig (d90b9dc)
  • 优化 Client (9229224)
  • 更新测试和示例代码 (959a21d) (08531ac)
  • 增加重连次数限制和优化重连延迟时间 (#32)

关于 PHPMQTT

  • MQTT 协议解析 & 协程客户端
  • 适用于 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~

猜你喜欢

转载自www.oschina.net/news/128004/phpmqtt-1-2-1-released