foolkaka/tail
Composer 安装命令:
composer require foolkaka/tail
包简介
RabbitMQ and PHP client for Laravel and Lumen that allows you to add and listen queues messages just simple
README 文档
README
RabbitMQ and PHP client for Laravel and Lumen that allows you to add and listen queues messages just simple.
Features
- Simple queue configuration
- Multiple server connections
- Add message to queues easily
- Listen queues with useful options
Requirements
- php-amqplib/php-amqplib: 2.*
Version
1.0.6
Installation
Preparation
Open your composer.json file and add the following to the require array:
"foolkaka/tail": "1.*"
Install dependencies
$ composer install
Or
$ composer update
Integration
Laravel
After installing the package, open your Laravel config file config/app.php and add the following lines.
In the $providers array add the following service provider for this package.
Foolkaka\Tail\ServiceProvider::class,
In the $aliases array add the following facade for this package.
'Tail' => Foolkaka\Tail\Facades\Tail::class,
Add servers connection file running:
$ php artisan vendor:publish --provider="Foolkaka\Tail\ServiceProvider" --tag="config"
Lumen
Register the Lumen Service Provider in bootstrap/app.php:
/* |-------------------------------------------------------------------------- | Register Service Providers |-------------------------------------------------------------------------- */ //... $app->configure('tail-settings'); $app->register(Foolkaka\Tail\LumenServiceProvider::class); //...
Make sure sure $app->withFacades(); is uncomment in your bootstrap/app.php file
Create a config folder in the root directory of your Lumen application and copy the content from vendor/foolkaka/tail/config/tail.php to config/tail-settings.php.
RabbitMQ Connections
By default the library will use the RabbitMQ installation credentials (on a fresh installation the user "guest" is created with password "guest").
To override the default connection or add more servers, edit the RabbitMQ connections file at: config/tail-settings.php
return array( 'default' => 'default_connection', 'connections' => array( 'default_connection' => array( 'host' => 'localhost', 'port' => 5672, 'username' => 'guest', 'password' => 'guest', 'vhost' => '/', 'exchange' => 'default_exchange_name', 'consumer_tag' => 'consumer', 'exchange_type'=> 'direct', 'content_type' => 'text/plain', 'ssl_connect' => false, 'ssl_options' => [ 'cafile' => '/opt/certs/ca.cert.pem', 'local_cert' => '/opt/certs/local_cert.pem', 'verify_peer' => true, 'verify_peer_name' => false, 'allow_self_signed' => true ] ), 'other_server' => array( 'host' => '192.168.0.10', 'port' => 5672, 'username' => 'guest', 'password' => 'guest', 'vhost' => '/', 'exchange' => 'default_exchange_name', 'consumer_tag' => 'consumer', 'exchange_type'=> 'fanout', 'content_type' => 'application/json', 'ssl_connect' => false, 'ssl_options' => [ 'cafile' => '/opt/certs/ca.cert.pem', 'local_cert' => '/opt/certs/local_cert.pem', 'verify_peer' => true, 'verify_peer_name' => false, 'allow_self_signed' => true ] ), ), );
Adding messages to queue:
Adding a simple message
Tail::add('queue-name', 'message');
Adding message changing RabbitMQ server
Tail::add('queue-name', 'message', array('connection_name' => 'connection_name_config_file'));
Adding message with different exchange
Tail::add('queue-name', 'message', array('exchange' => 'exchange_name'));
Adding message with different content type
Tail::add('queue-name', '{ 'message' : 'message' }', array('content_type' => 'application/json'));
Adding message with different options
$options = array ( 'connection_name' => 'connection_name_config_file', 'exchange' => 'exchange_name', 'vhost' => 'vhost' ); Tail::add('queue-name', 'message', $options);
Using Tail object
$message = new Tail::createMessage; $message->queue_name = 'queue-name'; $message->message = 'message'; $message->connection_name = 'connection_name_in_config_file'; $message->exchange = 'exchange_name'; $message->vhost = 'vhost'; $message->content_type = 'content/type' $message->save();
Listening queues:
Closure based listener
Tail::listen('queue-name', function ($message) { //Your message logic code });
Closure listener with options
$options = array( 'message_limit' => 50, 'time' => 60, 'empty_queue_timeout' => 5, 'connection_name' => 'connection_name_in_config_file', 'exchange' => 'exchange_name', 'vhost' => 'vhost' ); Tail::listenWithOptions('queue-name', $options, function ($message) { //Your message logic code });
Options definitions:
| Name | Description | Default value |
|---|---|---|
| queue_name | Queue name on RabbitMQ | * Required |
| message_limit | Number of messages to be processed | 0: Unlimited |
| time | Time in seconds the process will be running | 0: Unlimited |
| empty_queue_timeout | Time in seconds to kill listening when the queue is empty | 0: Unlimited |
| connection_name | Server connection name | Defined at connections file |
| exchange | Exchange name on RabbitMQ Server | Specified on connections file |
| vhost | Virtual host on RabbitMQ Server | Specified on connections file |
By default the listen process will be running forever unless you specify one of the running time arguments above (message_limit, time, empty_queue_timeout). They can be mixed all together, so when one of the condition is met the process will be stopped.
License
This package is open-sourced software licensed under the MIT license
foolkaka/tail 适用场景与选型建议
foolkaka/tail 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 10 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「queue」 「package」 「client」 「library」 「rabbitmq」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 foolkaka/tail 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 foolkaka/tail 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 foolkaka/tail 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP AMQP Binding Library
A Laravel package to monitor queue jobs.
Mock PSR-18 HTTP client
Asynchronous MQTT client built on React
Simple ASCII output of array data
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-10-27