定制 teclaelvis/rabbitmq-phalcon-adapter 二次开发

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

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

teclaelvis/rabbitmq-phalcon-adapter

最新稳定版本:1.0.4

Composer 安装命令:

composer require teclaelvis/rabbitmq-phalcon-adapter

包简介

Adapter package for phalcon project

README 文档

README

Adapter for phalcon queue manager

Installation

composer require teclaelvis/rabbitmq-phalcon-adapter:1.0.2

Initial configuration

We need to create a new instance of the QueueManagerFactory class and pass the adapter as a parameter.

use Pmqelvis\QueueManagerFactory;
use Pmqelvis\RabbitMQAdapter;

require __DIR__ . '/vendor/autoload.php';


// // create a new instance of the rabbitmq adapter

$adapter = new RabbitMQAdapter('localhost', 5672, 'guest', 'guest');
$queueFactory = new QueueManagerFactory($adapter);

If you are working with a ssl connection, you can use the follow code:

$adapter = new RabbitMQAdapter('localhost', 5672, 'guest', 'guest', true);
 
// continue with the configuration
...

in Phalcon we can use the QueueManagerFactory class as a service, for example:

$di->set('queue', function () use ($config) {
    $ssl = getenv('APPLICATION_ENV') != 'development';
    $adapter = new RabbitMQAdapter(
        $config->rabbitmq->host,
        $config->rabbitmq->port,
        $config->rabbitmq->user,
        $config->rabbitmq->password,
        $ssl
    );
    return new QueueManagerFactory($adapter);
});

and then we can use it in our logic to get the queue manager:

$queueFactory = $this->di->get('queue');

...

Producer configuration

The example below shows how to configure a producer

use Pmqelvis\QueueManagerFactory;
use Pmqelvis\RabbitMQAdapter;

require __DIR__ . '/vendor/autoload.php';


/**
 *  before we need get the QueueManagerFactory instance
 * $queueFactory = new QueueManagerFactory($adapter);
 */
...
...

$queue = $queueFactory->build('test', 'producer', 'test-exchange');
// or
$queue = $queueFactory->buildProducer('test' ,'test-exchange');
$queue->publish('Hello World from my library');
    

Consumer configuration

The example below shows how to configure a consumer

use Pmqelvis\QueueManagerFactory;
use Pmqelvis\RabbitMQAdapter;

require __DIR__ . '/vendor/autoload.php';


/**
 *  before we need get the QueueManagerFactory instance
 * $queueFactory = new QueueManagerFactory($adapter);
 */
...
...


$queue = $queueFactory->build('test','consumer' ,'test-exchange');
// or
$queue = $queueFactory->buildConsumer('test' ,'test-exchange');

$queue->consume(function ($message) {
    echo $message->body;
    $message->ack();
});
    

The code above will consume the messages from the queue and print the message body and $message->ack() will acknowledge the message.

RabbitMQAdapter options

Option Type Default Description
host string '' RabbitMQ host
port int 5672 RabbitMQ port
user string '' RabbitMQ user
password string '' RabbitMQ password
ssl bool false Enable ssl mode
options array [] RabbitMQ connection options

QueueManagerFactory options

The QueueManagerFactory->build() method accepts the following options:

Option Type Default Description
queueName string '' Queue name
type string '' Queue type (producer or consumer)
exchangeName string '' Exchange name
exchangeType string '' Exchange type

if type is consumer the method returns a ConsumeQueue instance, if type is producer the method returns a ProducerQueue instance.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固