ant-corp / mqtt-server
hyperf Mqtt服务端
dev-master
2021-03-29 03:31 UTC
Requires
- php: >=7.2
This package is auto-updated.
Last update: 2025-03-29 00:51:31 UTC
README
安装
$ composer require ant-corp/mqtt-server
使用
在 config/server.php 添加
use AntCorp\MqttServer\Events\MqttServer; use AntCorp\MqttServer\Protocol\Types; use AntCorp\MqttServer\Version\V3; [ 'name' => 'mqtt', 'type' => Server::SERVER_BASE, 'host' => '0.0.0.0', 'version' => V3::class, 'port' => 9601, 'sock_type' => SWOOLE_SOCK_TCP, 'callbacks' => [ Event::ON_RECEIVE => [AntCorp\MqttServer\Server::class, 'onReceive'], ], 'receiveCallbacks' => [ Types::CONNECT => [MqttServer::class, 'onMqConnect'], Types::PINGREQ => [MqttServer::class, 'onMqPingreq'], Types::DISCONNECT => [MqttServer::class, 'onMqDisconnect'], Types::PUBLISH => [MqttServer::class, 'onMqPublish'], Types::SUBSCRIBE => [MqttServer::class, 'onMqSubscribe'], Types::UNSUBSCRIBE => [MqttServer::class, 'onMqUnsubscribe'], ], 'settings' => [ 'open_mqtt_protocol' => true, // 启用 EOF 自动分包 'package_eof' => "\r\n", // 设置 EOF 字符串 'package_max_length' => 2000000, ], ]