49 lines
1.9 KiB
PHP
49 lines
1.9 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | YwxApp [ WE CAN DO IT JUST THINK ]
|
||
// +----------------------------------------------------------------------
|
||
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
|
||
// +----------------------------------------------------------------------
|
||
// | Author: ywxapp<admin@ywxapp.cn>
|
||
// +----------------------------------------------------------------------
|
||
namespace addon\mqttbroker\command;
|
||
|
||
use think\console\Command;
|
||
use think\console\Input;
|
||
use think\console\Output;
|
||
use think\console\input\Option;
|
||
use addon\mqttbroker\service\Broker;
|
||
|
||
/**
|
||
* 启动 MQTT Broker 常驻进程(兼容 MQTT 3.1.1 / 5.0,类 EMQX 轻量 broker)
|
||
* php think mqttbroker:start
|
||
* php think mqttbroker:start -p 1883
|
||
*
|
||
* 依赖:仅 Workerman\Worker(框架已自带,无需 composer require workerman/mqtt)。
|
||
* 手动发布经 DB 出站队列内部路由,零外部依赖;仅"转发规则(桥接 EMQX)"
|
||
* 需要 workerman/mqtt(composer require workerman/mqtt),未安装时自动跳过转发。
|
||
*/
|
||
class MqttBroker extends Command
|
||
{
|
||
|
||
protected function configure()
|
||
{
|
||
$this->setName('mqttbroker:start')
|
||
->addOption('port', 'p', Option::VALUE_OPTIONAL, '监听端口', 1883)
|
||
->addOption('host', 'H', Option::VALUE_OPTIONAL, '监听地址', '0.0.0.0')
|
||
->setDescription('启动 MQTT Broker 服务 (MQTT 3.1.1 / 5.0)');
|
||
}
|
||
|
||
|
||
protected function execute(Input $input, Output $output)
|
||
{
|
||
$port = (int) $input->getOption('port');
|
||
$host = $input->getOption('host');
|
||
$output->writeln("启动 MQTT Broker on {$host}:{$port}(协议 MQTT 3.1.1 / 5.0)");
|
||
$output->writeln("按 Ctrl+C 停止(Windows 下为单进程调试模式)");
|
||
|
||
(new Broker())->start($host, $port);
|
||
return 0;
|
||
}
|
||
}
|