kontoulis/rabbitmq-laravel
Composer 安装命令:
composer require kontoulis/rabbitmq-laravel
包简介
RabbitMQ Broker for Laravel
README 文档
README
Installation
Via Composer
$ composer require kontoulis/rabbitmq-laravel
Add the Service Provider to config/app.php
Kontoulis\RabbitMQLaravel\RabbitMQLaravelServiceProvider::class,
Add the RabbitMQ facade to config/app.php
'RabbitMQ' => Kontoulis\RabbitMQLaravel\Facades\RabbitMQ::class,
Publish the configuration file and edit it if needed in config/rabbitmq-laravel.php
$ php artisan vendor:publish
Usage
- Routing Key / Queue Name
The default routing key can be set in config file, or env("APP_NAME")."_queue") will be used.
Also most methods take argument $routingKey which can override the default.
RabbitMQ::setRoutingKey("myRoutingKey/queueName");
- Exchange
If you don't set an exchange the default '' exchange will be used.
If you set one, make sure the bindings are set in RabbitMQ system.
if you are not familiar with exchanges you will probably do not need to set that.
RabbitMQ::setExchange("myExchange")'
You can use the RabbitMQ facade to do anything as seen in https://github.com/php-amqplib/php-amqplib/blob/master/PhpAmqpLib/Channel/AMQPChannel.php . Basically, the RabbitMQ facade uses the Broker class which is an extension of AMQPChannel.
- Publishing
// Single message $msg = [ "key1" => "value1", "key2" => "value2" ]; RabbitMQ::publishMesssage($msg); // OR RabbitMQ::publishMessage($msg, "myRoutingKey"); // Batch publishing $messages = [ [ "messsage_1_key1" => "value1", "messsage_1_key2" => "value2" ], [ "messsage_2_key1" => "value1", "messsage_2_key2" => "value2" ] ]; RabbitMQ::publishBatch($messages); // OR RabbitMQ::publishBatch($messages, "myRoutingKey");
- Consuming the Queue
In order to consume the queue, you could either use the AmqpChannel through the Facade, or use a better to manage approach with QueueHandlers. A QueueHandler should extend the Kontoulis\RabbitMQLaravel\Handlers\Handler class and the built-in ListenToQueue method accepts an array of handlers to process the queue message. If more than one handler exists in array, there are some Handler return values that will use the follow up QueueHandlers in cases of failure of the previous. There is also a Kontoulis\RabbitMQLaravel\Handlers\Handler\DefaultHandler class as example and/or debug handler.
namespace Kontoulis\RabbitMQLaravel\Handlers; use Kontoulis\RabbitMQLaravel\Message\Message; /** * Class DefaultHandler * @package Kontoulis\RabbitMQLaravel\Handlers */ class DefaultHandler extends Handler{ /** * Tries to process the incoming message. * @param Message $msg * @return int One of the possible return values defined as Handler * constants. */ public function process(Message $msg) { return $this->handleSuccess($msg); } /** * @param $msg * @return int */ protected function handleSuccess($msg) { var_dump($msg); /** * For more Handler return values see the parent class */ return Handler::RV_SUCCEED_STOP; } }
In order to Listen to the Queue you have to pass an array of Handlers to the method
$handlers = ["\\App\\QueueHandlers\\MyHandler"]; \RabbitMQ::listenToQueue($handlers);
License
The MIT License (MIT). Please see LICENCE.md for more information.
kontoulis/rabbitmq-laravel 适用场景与选型建议
kontoulis/rabbitmq-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.23k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2015 年 10 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「rabbitmq」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kontoulis/rabbitmq-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kontoulis/rabbitmq-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kontoulis/rabbitmq-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Work with RabbitMQ in Laravel.
Microservice RPC through message queues.
PHP AMQP Binding Library
Integrates php-amqplib with Symfony & RabbitMq. Formerly oldsound/rabbitmq-bundle.
Behat extention for RabbitMQ
Alfabank REST API integration
统计信息
- 总下载量: 1.23k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 16
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-03