Download the PHP package adamhutchison/laravel-mq-manager without Composer
On this page you can find all versions of the php package adamhutchison/laravel-mq-manager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download adamhutchison/laravel-mq-manager
More information about adamhutchison/laravel-mq-manager
Files in adamhutchison/laravel-mq-manager
Package laravel-mq-manager
Short Description MQ Manager for inter micro-service messaging in laravel
License MIT
Informations about the package laravel-mq-manager
Message Queue Manager For Laravel Microservices
Message queue manager (MQ Manager) is a package that allows asynchronous inter service messages to be sent by micro services built on the laravel framework.
By default the MQ managers uses RabbitMQ as the message broker using the following connection credentials:
host:localhost
port:5672
username:guest
password:guest
These can be be set manually via the following env values:
-
MQ_MANAGER_HOST
-
MQ_MANAGER_PORT
-
MQ_MANAGER_USERNAME
MQ_MANAGER_PASSWORD
Installation
The package can then be installed using composer:
composer require adamhutchison/laravel-mq-manager
Then run the following command:
php artisan mq-manager:install
This will publish the mqmanager.php
config file to the applications config folder
Then set the following environment variables in the applications .env
file:
-
MQ_MANAGER_QUEUE
- defines the default queue that you wish messages to be published to, this will default toqueue
MQ_MANAGER_SERVICE
- states the MQ service driver you wish to use to power your inter service messaging, the package usesrabbitmq
, we are looking to add ActiveMQ in the future.
Basic usage
Sending Messages
By default MQ Manager will attempt to send messages to the queue defined in the MQ_MANAGER_QUEUE
env variable,
however you may also pass a custom queue name as a second parameter to the sendMessage()
method on the MQManager
class.
It's important to know that the MQManager
class is a singleton so it should be resolved using Laravels service container
rather than using the new operator
Basic Example:
Receiving Messages
You can listen for messages sent by other services using the listen()
method on the
MQManager
class. By default MQ Manager will listen for messages sent to the queues registered
with the registerQueueListener()
method on the MQManager
class. This method expects two parameter,
the first is the name of the queue and the second is a closure that that the message will be passed to.
You may also pass in a custom queue and closure to the listen method. In this case only messages sent to the
specified queue will be listened for, all queues subscribed to in the the mqmanager.php
config
will be ignored.
Basic Example
Automatic Messaging For Models Events
MQ Manager includes functionality that allows messages to be automatically sent to the
when a model is created, updated or deleted. Simply add the MQManager\Events\ModelTraits\SendsMQMessages
to any model that you wish messages to be broadcast for.
MQ Messenger will then send a message in the following format to the queue defined in the .env file
Listening For Model Events
MQ Manager provides the following artisan command for listening for model events php artisan mq-manager:listen
.
This artisan command can be started and monitored using supervisor (in the same way that queue worker would) to allow for
model events to be detected from a different microservice.