nailfor / php-queue-client
PHP 的队列代理客户端库
v1.2.8
2021-09-28 10:53 UTC
Requires
- react/socket: ^1.1
Requires (Dev)
- phpunit/phpunit: ^5.0.0
README
phpQueueClient 是 AMQP 和 MQTT 队列服务器的客户端库。它基于 reactPHP 的 socket-client 实现。
目标
该项目的目标是提供一个易于使用的现代架构 PHP AMQP 和 MQTT 客户端,不使用任何 PHP 模块。原始想法来源于 https://github.com/oliverlorenz/phpMqttClient
-
是的,它正确支持了 QoS 协议
-
是的,它可以在一个数据包中处理大量数据
-
是的,它可以接收、ping、取消订阅和发布
-
协议规范: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/csprd02/mqtt-v3.1.1-csprd02.html
示例发布
use nailfor\queue\ClientFactory; use nailfor\queue\protocol\MQTT; class MQTTClass { public function subscribe() { $url = '127.0.0.1:5672'; $options = [ //'username' => '', //'password' => '', 'clientId' => 'php', 'cleanSession' => false, 'topics' => [ 'topic_name' => [ //this flag clear message after reciev. Default true //'clear' => false, 'qos' => 1, //only for MQTT 'message' => 'hello from topic', ], 'capital_name' => [ 'qos' => 2, //only for MQTT 'message' => 'hello from capital', ], ], ]; $protocol = new MQTT; //default AMQP ClientFactory::publish($url, $options, [$this, 'onError'], $protocol); } }
示例订阅
use nailfor\queue\ClientFactory; use nailfor\queue\protocol\MQTT; use Illuminate\Support\Facades\Log; class MQTTClass { public function onMessage($packet) { //... } public function onCapitalMessage($packet) { //... } public function onError($reason) { echo $reason->getMessage(). PHP_EOL; exit; } public function subscribe() { $url = '127.0.0.1:5672'; $options = [ //'username' => '', //'password' => '', 'clientId' => 'php', 'cleanSession' => false, 'topics' => [ 'topic_name' => [ //this flag clear message after reciev. Default true //'clear' => false, 'qos' => 1, //only for MQTT 'events' => [ 'PUBLISH' => [$this, 'onMessage'], ], ], 'capital_name' => [ 'qos' => 0, //only for MQTT 'events' => [ 'PUBLISH' => [$this, 'onCapitalMessage'], ], ], ], ]; $protocol = new MQTT; //default AMQP $logger = Log::channel('stderr'); //default null ClientFactory::run($url, $options, [$this, 'onError'], $protocol, $logger); } }
也提供了命令
ClientFactory::run //subscribe and get messages
ClientFactory::publish
ClientFactory::unsubscribe
ClientFactory::ping
Logger 支持 3 个级别的详细程度:通知、信息和调试。当然,您可以禁用它,在最后一个参数中设置 null
通知 - (2020 年 10 月 21 日)
当前工作
-
AMQP 实现
-
发布.. 尚未完成
-
订阅
-
取消订阅
-
MQTT 实现
-
- QoS 1
-
- QoS 2
-
订阅
-
取消订阅
-
发布