@@ -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.
@@ -254,17 +262,143 @@ class RabbitMQJob extends BaseJob
254262}
255263```
256264
265+ ### Use your own Connection
266+
267+ You can extend the built-in ` PhpAmqpLib\Connection\AMQPStreamConnection::class `
268+ or ` PhpAmqpLib\Connection\AMQPSLLConnection::class ` and within the connection config, you can define your own class.
269+ When you specify a ` connection ` key in the config, with your own class name, every connection will use your own class.
270+
271+ An example for the config:
272+
273+ ``` php
274+ 'connections' => [
275+ // ...
276+
277+ 'rabbitmq' => [
278+ // ...
279+
280+ 'connection' = > \App\Queue\Connection\MyRabbitMQConnection::class,
281+ ],
282+
283+ // ...
284+ ],
285+ ```
286+
287+ ### Default Queue
288+
289+ The connection does use a default queue with value 'default', when no queue is provided by laravel.
290+ It is possible to change te default queue by adding an extra parameter in the connection config.
291+
292+ ``` php
293+ 'connections' => [
294+ // ...
295+
296+ 'rabbitmq' => [
297+ // ...
298+
299+ 'queue' => env('RABBITMQ_QUEUE', 'default'),
300+ ],
301+
302+ // ...
303+ ],
304+ ```
305+
306+ ### Heartbeat
307+
308+ By default, your connection will be created with a heartbeat setting of ` 0 ` .
309+ You can alter the heartbeat settings by changing the config.
310+
311+ ``` php
312+
313+ 'connections' => [
314+ // ...
315+
316+ 'rabbitmq' => [
317+ // ...
318+
319+ 'options' => [
320+ // ...
321+
322+ 'heartbeat' => 10,
323+ ],
324+ ],
325+
326+ // ...
327+ ],
328+ ```
329+
330+ ### SSL Secure
331+
332+ If you need a secure connection to rabbitMQ server(s), you will need to add these extra config options.
333+
334+ ``` php
335+ 'connections' => [
336+ // ...
337+
338+ 'rabbitmq' => [
339+ // ...
340+
341+ 'secure' = > true,
342+ 'options' => [
343+ // ...
344+
345+ 'ssl_options' => [
346+ 'cafile' => env('RABBITMQ_SSL_CAFILE', null),
347+ 'local_cert' => env('RABBITMQ_SSL_LOCALCERT', null),
348+ 'local_key' => env('RABBITMQ_SSL_LOCALKEY', null),
349+ 'verify_peer' => env('RABBITMQ_SSL_VERIFY_PEER', true),
350+ 'passphrase' => env('RABBITMQ_SSL_PASSPHRASE', null),
351+ ],
352+ ],
353+ ],
354+
355+ // ...
356+ ],
357+ ```
358+
359+ ### Events after Database commits
360+
361+ To instruct Laravel workers to dispatch events after all database commits are completed.
362+
363+ ``` php
364+ 'connections' => [
365+ // ...
366+
367+ 'rabbitmq' => [
368+ // ...
369+
370+ 'after_commit' => true,
371+ ],
372+
373+ // ...
374+ ],
375+ ```
376+
377+ ### Lazy Connection
378+
379+ By default, your connection will be created as a lazy connection.
380+ If for some reason you don't want the connection lazy you can turn it off by setting the following config.
381+
382+ ``` php
383+ 'connections' => [
384+ // ...
385+
386+ 'rabbitmq' => [
387+ // ...
388+
389+ 'lazy' = > false,
390+ ],
391+
392+ // ...
393+ ],
394+ ```
395+
257396## Laravel Usage
258397
259398Once you completed the configuration you can use the Laravel Queue API. If you used other queue drivers you do not need to
260399change anything else. If you do not know how to use the Queue API, please refer to the official Laravel
261400documentation: http://laravel.com/docs/queues
262401
263- ## Laravel Horizon Usage
264-
265- Starting with 8.0, this package supports [ Laravel Horizon] ( http://horizon.laravel.com ) out of the box. Firstly, install
266- Horizon and then set ` RABBITMQ_WORKER ` to ` horizon ` .
267-
268402## Lumen Usage
269403
270404For Lumen usage the service provider should be registered manually as follow in ` bootstrap/app.php ` :
@@ -287,7 +421,7 @@ There are two ways of consuming messages.
287421Setup RabbitMQ using ` docker-compose ` :
288422
289423``` bash
290- docker- compose up -d rabbitmq
424+ docker compose up -d
291425```
292426
293427To run the test suite you can use the following commands:
@@ -304,7 +438,7 @@ composer test:unit
304438```
305439
306440If you receive any errors from the style tests, you can automatically fix most,
307- if not all of the issues with the following command:
441+ if not all the issues with the following command:
308442
309443``` bash
310444composer fix:style
0 commit comments