Download the PHP package maksimdimitrov/mdim-amqp-laravel without Composer
On this page you can find all versions of the php package maksimdimitrov/mdim-amqp-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download maksimdimitrov/mdim-amqp-laravel
More information about maksimdimitrov/mdim-amqp-laravel
Files in maksimdimitrov/mdim-amqp-laravel
Package mdim-amqp-laravel
Short Description Laravel service provider for php-amqplib to use RabbitMQ
License MIT
Informations about the package mdim-amqp-laravel
Laravel Service Provider for php-amqplib to use with RabbitMQ without Laravel queues.
It is developed for versions greater than Laravel 5.7
How to install
Option 1
Use
Option 2
Add to your composer.json file in "require" section:
and in "repositories" section:
Next:
Next step is to run to publish the config file in config/mdim_rabbitmq.php Check the available commands and with
The config in config/mdim_rabbitmq.php
You can have many connections: default, some-other-rabbitmq-service, etc...
How to use
You need to create a new job class which will act as consumer and hold the callback function when a message is received. The class has to extend and have function handle() implemented, which is the callback function. You can use the dependency container to inject services. You also need to define getConnectionName(), getQueueName() and getConsumerTag(), check AMQP docs for property descriptions https://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.consume getConnectionName() should return name of the connection from config/mdim_rabbitmq.php e.g. default or some-other-rabbitmq-service
All the static methods in you can rewrite for your consumer needs.
There are two examples ready to run. Check the job class which will consume messages after you start it. You can push messages with example command class
Start this example with a command in the console
Open another console and run a command
In the first console you should see the received message now.
After you write your job work class with example name you can start it with
Publishing messages can be done without commands, but also from your controller like this:
An example consumer class can be: