Package Data | |
---|---|
Maintainer Username: | david.krizanic |
Maintainer Contact: | david.krizanic@comlaude.com (David Krizanic) |
Package Create Date: | 2020-09-09 |
Package Last Update: | 2024-09-23 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-17 03:07:16 |
Package Statistics | |
---|---|
Total Downloads: | 11,365 |
Monthly Downloads: | 62 |
Daily Downloads: | 0 |
Total Stars: | 2 |
Total Watchers: | 8 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Simple PhpAmqpLib wrapper for interaction with RabbitMQ
Add the following to your require part within the composer.json:
"comlaude/laravel-amqp": "1.*"
$ php composer update
or
$ php composer require comlaude/laravel-amqp
Create a config folder in the root directory of your Lumen application and copy the content from vendor/comlaude/laravel-amqp/config/amqp.php to config/amqp.php.
Adjust the properties to your needs.
return [
'use' => 'production',
'properties' => [
'production' => [
'host' => 'localhost',
'port' => 5672,
'username' => 'guest',
'password' => 'guest',
'vhost' => '/',
'exchange' => 'amq.topic',
'exchange_type' => 'topic',
'consumer_tag' => 'consumer',
'ssl_options' => [], // See https://secure.php.net/manual/en/context.ssl.php
'connect_options' => [], // See https://github.com/php-amqplib/php-amqplib/blob/master/PhpAmqpLib/Connection/AMQPSSLConnection.php
'queue_properties' => ['x-ha-policy' => ['S', 'all']],
'exchange_properties' => [],
'timeout' => 0
],
],
];
Register the Lumen Service Provider in bootstrap/app.php:
/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
*/
//...
$app->configure('amqp');
$app->register(ComLaude\Amqp\LumenServiceProvider::class);
//...
Add Facade Support for Lumen 5.2+
//...
$app->withFacades(true, [
'ComLaude\Amqp\Facades\Amqp' => 'Amqp',
]);
//...
Open config/app.php and add the service provider and alias:
'ComLaude\Amqp\AmqpServiceProvider',
'Amqp' => 'ComLaude\Amqp\Facades\Amqp',
Amqp::publish('routing-key', 'message');
Amqp::publish('routing-key', 'message' , ['queue' => 'queue-name']);
Amqp::publish('routing-key', 'message' , ['exchange' => 'amq.direct']);
Amqp::consume(function ($message) {
var_dump($message->body);
Amqp::acknowledge($message);
});
Amqp::consume(function ($message) {
var_dump($message->body);
Amqp::acknowledge($message);
}, [
'timeout' => 2,
'vhost' => 'vhost3',
'queue' => 'queue-name',
'persistent' => true // required if you want to listen forever
]);
\Amqp::publish('', 'message' , [
'exchange_type' => 'fanout',
'exchange' => 'amq.fanout',
]);
This package is open-sourced software licensed under the MIT license