jmcnualan / amqp
forked php-amqplib wrapper that eases the consumption of RabbitMQ. A painless way of using RabbitMQ
v1.5.1
2021-07-08 04:04 UTC
Requires
- php: >=7.0
- illuminate/container: ^5.8|^6.0|^7.0|^8.0
- illuminate/pipeline: ^5.8|^6.0|^7.0|^8.0
- illuminate/support: ^5.8|^6.0|^7.0|^8.0
- laravel/helpers: ^1.2
- php-amqplib/php-amqplib: ^3.0
This package is not auto-updated.
Last update: 2024-09-13 17:36:48 UTC
README
anik/amqp
is a php-amqplib wrapper that eases the consumption of RabbitMQ. A painless way of using RabbitMQ.
You can use this package with
需求
This package requires the following
- php >= 7.0
- ext-bcmath
- ext-sockets
安装
The package works with Laravel, Lumen & Laravel zero. Install it via composer.
composer require anik/amqp
对于Laravel
The service provider will automatically get registered. Or you may manually add the service provider in your config/app.php
providers array
'providers' => [ /// ... Anik\Amqp\ServiceProviders\AmqpServiceProvider::class, ]
- 使用以下命令添加配置文件
amqp.php
到你的配置目录。
php artisan vendor:publish --provider="Anik\Amqp\ServiceProviders\AmqpServiceProvider"
对于Lumen
- 在您的
bootstrap/app.php
文件中添加服务提供者。
$app->register(Anik\Amqp\ServiceProviders\AmqpServiceProvider::class);
- 通过从
vendor/anik/amqp/src/config/amqp.php
复制配置amqp.php
到您的配置目录。别忘了在bootstrap/app.php
中添加$app->configure('amqp');
。
N.B: 对于Lumen,您不需要启用Facade。
对于Laravel Zero
- 在您的
config/app.php
providers 数组中添加提供者。
'providers' => [ /// ... Anik\Amqp\ServiceProviders\AmqpServiceProvider::class, ]
- 通过从
vendor/anik/amqp/src/config/amqp.php
复制配置amqp.php
到您的配置目录。
使用
- 发布消息
<?php // AmqpManager::publish($msg, $routing, $config); app('amqp')->publish('Message to direct exchange', 'routing-key', [ 'exchange' => [ 'type' => 'direct', 'name' => 'direct.exchange', ], ]);
- 消费消息
<?php use Anik\Amqp\ConsumableMessage; // AmqpManager::consume($consumerHandler, $bindingKey, $config); app('amqp')->consume(function (ConsumableMessage $message) { echo $message->getStream() . PHP_EOL; $message->getDeliveryInfo()->acknowledge(); }, 'routing-key', [ 'connection' => 'my-connection-name', 'exchange' => [ 'type' => 'direct', 'name' => 'direct.exchange', ], 'queue' => [ 'name' => 'direct.exchange.queue', 'declare' => true, 'exclusive' => false, ], 'qos' => [ 'enabled' => true, 'qos_prefetch_count' => 5, ], ]);
文档
The full documentation of this package is written in this article
问题和PR
人非圣贤,孰能无过。
- 如果该包生成任何问题,请报告。请说明重现问题的步骤。
- 如果您的PR丰富了该包或解决了任何现有问题,我很乐意合并它们。