xlabs/rabbitmqbundle
Composer 安装命令:
composer require xlabs/rabbitmqbundle
包简介
RabbitMQ wrapper bundle
README 文档
README
A Symfony2 RabbitMQ wrapper.
Installation
Install through composer:
php -d memory_limit=-1 composer.phar require xlabs/rabbitmqbundle
In your AppKernel
public function registerbundles()
{
return [
...
...
new XLabs\RabbitMQBundle\XLabsRabbitMQBundle(),
];
}
Configuration sample
Default values are shown below:
# app/config/config.yml
x_labs_rabbit_mq:
host: 192.168.5.26
port: 5672
vhost: '/'
user: admin
password: admin
exchange: gamification_exchange
api_port: 15672
queue_prefix: gamification_
Usage
First define your custom producer and its consumer:
# YourBundle/Resources/config/services.yml
...
my_custom_producer:
class: YourBundle\YourFolder\Producer
parent: xlabs_rmq_producer
shared: false
my_custom_consumer:
class: YourBundle\YourFolder\Consumer
tags:
- { name: console.command }
Your Producer class:
# YourBundle\YourFolder\Producer.php
namespace YourBundle\YourFolder;
use XLabs\RabbitMQBundle\RabbitMQ\Producer as Parent_Producer;
class Producer extends Parent_Producer
{
public static function getQueueName()
{
// set your custom queue name for this producer here
return 'my_custom_queue_name';
}
// if you need to modify the data sent in the message, create the following function
public function _process($data)
{
// here you can deal with the data in the message if needed before being consumed
}
}
Your Consumer class:
# YourBundle\YourFolder\Consumer.php
namespace YourBundle\YourFolder;
use XLabs\RabbitMQBundle\RabbitMQ\Consumer as Parent_Consumer;
class Consumer extends Parent_Consumer
{
// set your custom consumer command name
protected static $consumer = 'my_custom_name:bla_bla_bla';
// set a TTL > 0 to automatically close the consumer after period
// set TTL = 0 or dont set it to not close the consumer
protected $ttl = 0; // seconds
// following function is required as it is
protected function configure()
{
$this
->setName(self::$consumer)
;
}
// following function is required as it is
public function getQueueName()
{
return Producer::getQueueName();
}
public function callback($msg)
{
// this is all sample code to output something on screen
$container = $this->getApplication()->getKernel()->getContainer();
$msg = json_decode($msg->body);
echo "\n".$this->getQueueName()." - ".date('H:i:s d-m-Y')."\n";
echo "--------------------------------------------\n";
foreach($msg as $i => $tracker_item)
{
echo $i." : ".$tracker_item."\n";
}
}
}
At this point you can already call your producer:
$container->get('my_custom_producer')->process(array(
'key1' => 'value1',
'key2' => 'value2',
'key3' => 'value3'
));
And running the consumer:
php app/console my_custom_name:bla_bla_bla
Requirements
Make sure to add "management" tag to the rabbitmq user in order to use the API.
sudo rabbitmqctl set_user_tags USERNAME management
xlabs/rabbitmqbundle 适用场景与选型建议
xlabs/rabbitmqbundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 12 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「xlabs rabbitmq bundle」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 xlabs/rabbitmqbundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 xlabs/rabbitmqbundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 xlabs/rabbitmqbundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Work with RabbitMQ in Laravel.
Microservice RPC through message queues.
2lenet/EasyAdminPlusBundle
PHP AMQP Binding Library
The bundle for easy using json-rpc api on your project
Provide a way to secure accesses to all routes of an symfony application.
统计信息
- 总下载量: 1k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 10
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-12-15