@@ -3,7 +3,6 @@ RabbitMQ Queue driver for Laravel
33[ ![ Latest Stable Version] ( https://poser.pugx.org/vladimir-yuldashev/laravel-queue-rabbitmq/v/stable?format=flat-square )] ( https://packagist.org/packages/vladimir-yuldashev/laravel-queue-rabbitmq )
44[ ![ Build Status] ( https://github.com/vyuldashev/laravel-queue-rabbitmq/workflows/Tests/badge.svg )] ( https://github.com/vyuldashev/laravel-queue-rabbitmq/actions )
55[ ![ Total Downloads] ( https://poser.pugx.org/vladimir-yuldashev/laravel-queue-rabbitmq/downloads?format=flat-square )] ( https://packagist.org/packages/vladimir-yuldashev/laravel-queue-rabbitmq )
6- [ ![ StyleCI] ( https://styleci.io/repos/14976752/shield )] ( https://styleci.io/repos/14976752 )
76[ ![ License] ( https://poser.pugx.org/vladimir-yuldashev/laravel-queue-rabbitmq/license?format=flat-square )] ( https://packagist.org/packages/vladimir-yuldashev/laravel-queue-rabbitmq )
87
98## Support Policy
@@ -24,18 +23,19 @@ composer require vladimir-yuldashev/laravel-queue-rabbitmq
2423
2524The package will automatically register itself.
2625
26+ ### Configuration
27+
2728Add connection to ` config/queue.php ` :
2829
30+ > This is the minimal config for the rabbitMQ connection/driver to work.
31+
2932``` php
3033'connections' => [
3134 // ...
3235
3336 'rabbitmq' => [
3437
3538 'driver' => 'rabbitmq',
36- 'queue' => env('RABBITMQ_QUEUE', 'default'),
37- 'connection' => PhpAmqpLib\Connection\AMQPLazyConnection::class,
38-
3939 'hosts' => [
4040 [
4141 'host' => env('RABBITMQ_HOST', '127.0.0.1'),
@@ -44,33 +44,17 @@ Add connection to `config/queue.php`:
4444 'password' => env('RABBITMQ_PASSWORD', 'guest'),
4545 'vhost' => env('RABBITMQ_VHOST', '/'),
4646 ],
47+ // ...
4748 ],
48-
49- 'options' => [
50- 'ssl_options' => [
51- 'cafile' => env('RABBITMQ_SSL_CAFILE', null),
52- 'local_cert' => env('RABBITMQ_SSL_LOCALCERT', null),
53- 'local_key' => env('RABBITMQ_SSL_LOCALKEY', null),
54- 'verify_peer' => env('RABBITMQ_SSL_VERIFY_PEER', true),
55- 'passphrase' => env('RABBITMQ_SSL_PASSPHRASE', null),
56- ],
57- 'queue' => [
58- 'job' => VladimirYuldashev\LaravelQueueRabbitMQ\Queue\Jobs\RabbitMQJob::class,
59- ],
60- ],
61-
62- /*
63- * Set to "horizon" if you wish to use Laravel Horizon.
64- */
65- 'worker' => env('RABBITMQ_WORKER', 'default'),
66- 'after_commit' => false,
49+
50+ // ...
6751 ],
6852
6953 // ...
7054],
7155```
7256
73- ### Optional Config
57+ ### Optional Queue Config
7458
7559Optionally add queue options to the config of a connection.
7660Every queue created for this connection, gets the properties.
@@ -164,6 +148,30 @@ by adding extra options.
164148],
165149```
166150
151+ ### Horizon support
152+ Starting with 8.0, this package supports [ Laravel Horizon] ( http://horizon.laravel.com ) out of the box. Firstly, install
153+ Horizon and then set ` RABBITMQ_WORKER ` to ` horizon ` .
154+
155+ Horizon is depending on events dispatched by the worker.
156+ These events inform Horizon what was done with the message/job.
157+
158+ This Library supports Horizon, but in the config you have to inform Laravel to use the QueueApi compatible with horizon.
159+
160+ ``` php
161+ 'connections' => [
162+ // ...
163+
164+ 'rabbitmq' => [
165+ // ...
166+
167+ /* Set to "horizon" if you wish to use Laravel Horizon. */
168+ 'worker' => env('RABBITMQ_WORKER', 'default'),
169+ ],
170+
171+ // ...
172+ ],
173+ ```
174+
167175### Use your own RabbitMQJob class
168176
169177Sometimes you have to work with messages published by another application.
@@ -278,6 +286,136 @@ class RabbitMQJob extends BaseJob
278286 return '';
279287 }
280288}
289+
290+ ### Use your own Connection
291+
292+ You can extend the built-in `PhpAmqpLib\Connection\AMQPStreamConnection::class`
293+ or `PhpAmqpLib\Connection\AMQPSLLConnection::class` and within the connection config, you can define your own class.
294+ When you specify a `connection` key in the config, with your own class name, every connection will use your own class.
295+
296+ An example for the config:
297+
298+ ```php
299+ 'connections' => [
300+ // ...
301+
302+ 'rabbitmq' => [
303+ // ...
304+
305+ 'connection' = > \App\Queue\Connection\MyRabbitMQConnection::class,
306+ ],
307+
308+ // ...
309+ ],
310+ ```
311+
312+ ### Default Queue
313+
314+ The connection does use a default queue with value 'default', when no queue is provided by laravel.
315+ It is possible to change te default queue by adding an extra parameter in the connection config.
316+
317+ ``` php
318+ 'connections' => [
319+ // ...
320+
321+ 'rabbitmq' => [
322+ // ...
323+
324+ 'queue' => env('RABBITMQ_QUEUE', 'default'),
325+ ],
326+
327+ // ...
328+ ],
329+ ```
330+
331+ ### Heartbeat
332+
333+ By default, your connection will be created with a heartbeat setting of ` 0 ` .
334+ You can alter the heartbeat settings by changing the config.
335+
336+ ``` php
337+
338+ 'connections' => [
339+ // ...
340+
341+ 'rabbitmq' => [
342+ // ...
343+
344+ 'options' => [
345+ // ...
346+
347+ 'heartbeat' => 10,
348+ ],
349+ ],
350+
351+ // ...
352+ ],
353+ ```
354+
355+ ### SSL Secure
356+
357+ If you need a secure connection to rabbitMQ server(s), you will need to add these extra config options.
358+
359+ ``` php
360+ 'connections' => [
361+ // ...
362+
363+ 'rabbitmq' => [
364+ // ...
365+
366+ 'secure' = > true,
367+ 'options' => [
368+ // ...
369+
370+ 'ssl_options' => [
371+ 'cafile' => env('RABBITMQ_SSL_CAFILE', null),
372+ 'local_cert' => env('RABBITMQ_SSL_LOCALCERT', null),
373+ 'local_key' => env('RABBITMQ_SSL_LOCALKEY', null),
374+ 'verify_peer' => env('RABBITMQ_SSL_VERIFY_PEER', true),
375+ 'passphrase' => env('RABBITMQ_SSL_PASSPHRASE', null),
376+ ],
377+ ],
378+ ],
379+
380+ // ...
381+ ],
382+ ```
383+
384+ ### Events after Database commits
385+
386+ To instruct Laravel workers to dispatch events after all database commits are completed.
387+
388+ ``` php
389+ 'connections' => [
390+ // ...
391+
392+ 'rabbitmq' => [
393+ // ...
394+
395+ 'after_commit' => true,
396+ ],
397+
398+ // ...
399+ ],
400+ ```
401+
402+ ### Lazy Connection
403+
404+ By default, your connection will be created as a lazy connection.
405+ If for some reason you don't want the connection lazy you can turn it off by setting the following config.
406+
407+ ``` php
408+ 'connections' => [
409+ // ...
410+
411+ 'rabbitmq' => [
412+ // ...
413+
414+ 'lazy' = > false,
415+ ],
416+
417+ // ...
418+ ],
281419```
282420
283421## Laravel Usage
@@ -286,11 +424,6 @@ Once you completed the configuration you can use the Laravel Queue API. If you u
286424change anything else. If you do not know how to use the Queue API, please refer to the official Laravel
287425documentation: http://laravel.com/docs/queues
288426
289- ## Laravel Horizon Usage
290-
291- Starting with 8.0, this package supports [ Laravel Horizon] ( http://horizon.laravel.com ) out of the box. Firstly, install
292- Horizon and then set ` RABBITMQ_WORKER ` to ` horizon ` .
293-
294427## Lumen Usage
295428
296429For Lumen usage the service provider should be registered manually as follow in ` bootstrap/app.php ` :
@@ -313,7 +446,7 @@ There are two ways of consuming messages.
313446Setup RabbitMQ using ` docker-compose ` :
314447
315448``` bash
316- docker- compose up -d rabbitmq
449+ docker compose up -d
317450```
318451
319452To run the test suite you can use the following commands:
@@ -330,7 +463,7 @@ composer test:unit
330463```
331464
332465If you receive any errors from the style tests, you can automatically fix most,
333- if not all of the issues with the following command:
466+ if not all the issues with the following command:
334467
335468``` bash
336469composer fix:style
0 commit comments