承接 vrnvgasu/php-rabbit-handler 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

vrnvgasu/php-rabbit-handler

Composer 安装命令:

composer require vrnvgasu/php-rabbit-handler

包简介

Handle queues

README 文档

README

composer require vrnvgasu/php-rabbit-handler

Look examples in ./Examples.

Connection

Create new connection.

$connection = new Connection('localhost', 5672, 'guest', 'guest');

Queue

Create new queue.

$queue = new Queue('hello', false, false, false, false);

Pass '' as the first variable if you need a unique queue from rabbit.

Exchange

Create new exchange.

$exchange = new Exchange('direct_logs', 'direct', false, false, false);

Bind queue and exchange

Create new binding.

$binding = new Binding();

You can create pass routing key in your binding.

$binding = new Binding('key');

Then you must to create helper and pass him $connection, $queue, $exchange and $binding.

$helper = new AMQPHelper($connection, $queue, $exchange, $binding);

Consuming

Create new consume.

$consume = new Consume('', false, false,false, false);

You can pass callback function in Consume constructor to handle message from rabbit

$consume = new Consume('', false, false, false, false, function($msg) {
    print_r('Message: ' . $msg->body);
});

Or you can extend your consumer class from Consumer and declare callback method.

class TestConsumer extends Consumer
{
    /**
     * @param AMQPMessage $msg
     */
    public function callback(AMQPMessage $msg): void
    {
        print_r(' [x] Received ' . $msg->body . "\n");

        if (!$this->consume->getNoAck()) {
            $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
        }
    }
}

Then you must to create consumer and pass him $helper and $consume.

$consumer = new Consumer($helper, $publication);

Then call method execute.

$consumer->execute();

If you want to interrupt the execution of the handler after a while, then use:

$seconds = 60;
$consumer->execute(true, null, false, $seconds);

This will interrupt execution after the specified time after processing the last message.

Producing

Create new publication.

$publication = new Publication([], 'hello');

Then you must to create producer and pass him $helper and $publication.

$producer = new Producer($helper, $consume);

You need payload for your producer. Producer can get payload from objects which implements JobInterface.

You can pass your job object to Producer object

$producer->execute(TestJob::dispatch($param));

Or you can pass producer to the method execute.

TestJob::dispatch($param)->execute($producer);

Job

Prepare payload for producer.

Dispatch

At the first you need to transfer data for preparation to dispatch.

use ATC\Jobs\TestJob;

TestJob::dispatch($param1, $param2, $param3);

Class declaration

Your TestJob must extends from Job

class TestJob extends BaseJob
{
    //
}

Handling

In TestJob you must to declare method handle with params which you pass in dispatch. handle will execute in dispatch.

    protected function handle($param1, $param2, $param3)
    {
        // Parameters will be passed to this class automatically
        // You can do something with them and get some $data
        
        // In the same method, you need to transfer the payload to the method `payload` for `producer`
        $this->setPayload($data);
    }

vrnvgasu/php-rabbit-handler 适用场景与选型建议

vrnvgasu/php-rabbit-handler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.6k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 02 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「queue」 「rabbitmq」 「message」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 vrnvgasu/php-rabbit-handler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 vrnvgasu/php-rabbit-handler 我们能提供哪些服务?
定制开发 / 二次开发

基于 vrnvgasu/php-rabbit-handler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-05