mihai-valentin / laravel-rabbitmq-notification-channel
Simple Laravel RabbitMQ Notification Channel
Installs: 1 162
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^8.0
- illuminate/contracts: ^9.0
- illuminate/notifications: ^9.0
- illuminate/support: ^9.0
- php-amqplib/php-amqplib: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.13
- orchestra/testbench: ^7.0
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-10-25 19:47:32 UTC
README
Simple Laravel RabbitMQ Notification Channel. Imagine you want to send a Laravel notification via rabbitmq. Now you can
use this simple package without caring about an individual channel and connections. Just create a message and send
via rabbitmq
channel.
Installation
Get the package
composer require mihai-valentin/laravel-rabbitmq-notification-channel
Publish configuration
php artisan rabbitmq-notification-channel:publish
Note You can use
--force
option to overwrite existing files
Configuration
To start using the rabbitmq
channel you have to configure it. There are two ways of configuration using config file
and using environment variables.
The config file options:
default_queue
- the name of the queue that for messagesrabbitmq
- an array of RabbitMQ connection parameters (host, port, user and password)
Alternatively you can set all the config using your .env
file:
RABBITMQ_NOTIFICATION_DEFAULT_QUEUE=queue RABBITMQ_NOTIFICATION_HOST=localhost RABBITMQ_NOTIFICATION_PORT=5672 RABBITMQ_NOTIFICATION_USER=guest RABBITMQ_NOTIFICATION_PASSWORD=guest
Instantaneously Start
If you have to create a notification from scratch, then just run an artisan command:
php artisan make:notification:rabbitmq
Then implement the toRabbitMQ
method. Note that it must return a LaravelRabbitmqNotificationChannel\Message\Message
implementation.
Quick Start
- Add the
LaravelRabbitmqNotificationChannel\RabbitMQNotification
interface to your notification - Add
rabbitmq
channel to the notification's via array - Implement the
toRabbitMQ
method respecting theLaravelRabbitmqNotificationChannel\RabbitMQNotification
interface - Implement the
LaravelRabbitmqNotificationChannel\Message\Message
interface and use the implementation in thetoRabbitMQ
method - Notify your notifiables
Contracts
The LaravelRabbitmqNotificationChannel\RabbitMQNotification
interface represents a generic contract for notifications.
It declares how to get a message to send it via the channel. In other words, if you have to send a notification using
the rabbitmq
channel you have to implement this interface.
The LaravelRabbitmqNotificationChannel\Message\Message
interface is a message abstraction. It declares the way of
providing its content. Every message that has to be sent via rabbitmq
channel must implement it.
The LaravelRabbitmqNotificationChannel\RabbitMQNotification\Channel
interface represents the rabbitmq notification
channel interface. You can use it to implement you own channel.
The LaravelRabbitmqNotificationChannel\Broker\Publisher
interface represents the RabbitMQ messages publishing
contract. You can use it to overwrite default publisher.
The LaravelRabbitmqNotificationChannel\Mapper\MessageMapper
interface tells about "Message to AMQPMessage" mapping
rules. You can also use it to overwrite the default mapper.
RabbitMQ Connection
The LaravelRabbitmqNotificationChannel\Broker\RabbitMQConnection
class represents basic RabbitMQ connection
abstraction. You can extend it to overwrite the message delivery scenario.
Code of Conduct
In order to ensure that the community is welcoming to all, please review and abide by the Code of Conduct.
Contributing
TBD;
License
The MIT License (MIT). Please see License File for more information.