Package Data | |
---|---|
Maintainer Username: | du-disk |
Maintainer Contact: | dudyiskandar325@gmail.com (Dudi.I) |
Package Create Date: | 2022-11-30 |
Package Last Update: | 2022-11-30 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-24 15:08:09 |
Package Statistics | |
---|---|
Total Downloads: | 772 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
AMQP wrapper for Laravel and Lumen to publish and consume messages especially from RabbitMQ
Add the following to your require part within the composer.json:
"du-disk/laravel-amqp-delay-message": "2.*" (Laravel >= 5.5)
"du-disk/laravel-amqp-delay-message": "1.*" (Laravel < 5.5)
$ php composer update
or
$ php composer require du-disk/laravel-amqp-delay-message
Create a config folder in the root directory of your Lumen application and copy the content from vendor/du-disk/laravel-amqp-delay-message/config/amqp.php to config/amqp.php.
Adjust the properties to your needs.
return [
'use' => 'production',
'properties' => [
'production' => [
'host' => 'localhost',
'port' => 5672,
'username' => 'username',
'password' => 'password',
'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(Brodud\Amqp\LumenServiceProvider::class);
//...
Add Facade Support for Lumen 5.2+
//...
$app->withFacades(true, [
'Brodud\Amqp\Facades\Amqp' => 'Amqp',
]);
//...
Open config/app.php and add the service provider and alias:
'Brodud\Amqp\AmqpServiceProvider',
'Amqp' => 'Brodud\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('queue-name', function ($message, $resolver) {
var_dump($message->body);
$resolver->acknowledge($message);
$resolver->stopWhenProcessed();
});
Amqp::consume('queue-name', function ($message, $resolver) {
var_dump($message->body);
$resolver->acknowledge($message);
});
Amqp::consume('queue-name', function ($message, $resolver) {
var_dump($message->body);
$resolver->acknowledge($message);
}, [
'timeout' => 2,
'vhost' => 'vhost3'
]);
\Amqp::publish('', 'message' , [
'exchange_type' => 'fanout',
'exchange' => 'amq.fanout',
]);
\Amqp::consume('', function ($message, $resolver) {
var_dump($message->body);
$resolver->acknowledge($message);
}, [
'routing' => '',
'exchange' => 'amq.fanout',
'exchange_type' => 'fanout',
'queue_force_declare' => true,
'queue_exclusive' => true,
'persistent' => true // required if you want to listen forever
]);
This package is open-sourced software licensed under the MIT license