定制 nailfor/php-queue-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nailfor/php-queue-client

Composer 安装命令:

composer require nailfor/php-queue-client

包简介

a queue broker client library for php

README 文档

README

phpQueueClient is an client library for AMQP and MQTT queues server. Its based on the reactPHP socket-client

Goal

Goal of this project is easy to use both AMQP and MQTT client for PHP in a modern architecture without using any php modules. Original idea taken from https://github.com/oliverlorenz/phpMqttClient

Example publish

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);
    }
}

Example subscribe

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);
    }
}

also commands are available

ClientFactory::run //subscribe and get messages

ClientFactory::publish

ClientFactory::unsubscribe

ClientFactory::ping

The Logger suppurt 3 level of details: notice, info and debug. Offcourse you can disable it set null in last param

Notice - (Oct 21th, 2020)

Currently work:

  • AMQP implementation:

  • publish.. not yet

  • subscribe

  • unsubscribe

  • MQTT implementation:

    • qos 1
    • qos 2
  • subscribe

  • unsubscribe

  • publish

统计信息

  • 总下载量: 1.31k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2019-11-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固