@@ -3,7 +3,6 @@ RabbitMQ Queue driver for Laravel
3
3
[ ![ 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 )
4
4
[ ![ Build Status] ( https://github.com/vyuldashev/laravel-queue-rabbitmq/workflows/Tests/badge.svg )] ( https://github.com/vyuldashev/laravel-queue-rabbitmq/actions )
5
5
[ ![ 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 )
7
6
[ ![ License] ( https://poser.pugx.org/vladimir-yuldashev/laravel-queue-rabbitmq/license?format=flat-square )] ( https://packagist.org/packages/vladimir-yuldashev/laravel-queue-rabbitmq )
8
7
9
8
## Support Policy
@@ -24,18 +23,19 @@ composer require vladimir-yuldashev/laravel-queue-rabbitmq
24
23
25
24
The package will automatically register itself.
26
25
26
+ ### Configuration
27
+
27
28
Add connection to ` config/queue.php ` :
28
29
30
+ > This is the minimal config for the rabbitMQ connection/driver to work.
31
+
29
32
``` php
30
33
'connections' => [
31
34
// ...
32
35
33
36
'rabbitmq' => [
34
37
35
38
'driver' => 'rabbitmq',
36
- 'queue' => env('RABBITMQ_QUEUE', 'default'),
37
- 'connection' => PhpAmqpLib\Connection\AMQPLazyConnection::class,
38
-
39
39
'hosts' => [
40
40
[
41
41
'host' => env('RABBITMQ_HOST', '127.0.0.1'),
@@ -44,33 +44,17 @@ Add connection to `config/queue.php`:
44
44
'password' => env('RABBITMQ_PASSWORD', 'guest'),
45
45
'vhost' => env('RABBITMQ_VHOST', '/'),
46
46
],
47
+ // ...
47
48
],
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
+ // ...
67
51
],
68
52
69
53
// ...
70
54
],
71
55
```
72
56
73
- ### Optional Config
57
+ ### Optional Queue Config
74
58
75
59
Optionally add queue options to the config of a connection.
76
60
Every queue created for this connection, gets the properties.
@@ -164,6 +148,30 @@ by adding extra options.
164
148
],
165
149
```
166
150
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
+
167
175
### Use your own RabbitMQJob class
168
176
169
177
Sometimes you have to work with messages published by another application.
@@ -278,6 +286,136 @@ class RabbitMQJob extends BaseJob
278
286
return '';
279
287
}
280
288
}
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
+ ],
281
419
```
282
420
283
421
## Laravel Usage
@@ -286,11 +424,6 @@ Once you completed the configuration you can use the Laravel Queue API. If you u
286
424
change anything else. If you do not know how to use the Queue API, please refer to the official Laravel
287
425
documentation: http://laravel.com/docs/queues
288
426
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
-
294
427
## Lumen Usage
295
428
296
429
For 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.
313
446
Setup RabbitMQ using ` docker-compose ` :
314
447
315
448
``` bash
316
- docker- compose up -d rabbitmq
449
+ docker compose up -d
317
450
```
318
451
319
452
To run the test suite you can use the following commands:
@@ -330,7 +463,7 @@ composer test:unit
330
463
```
331
464
332
465
If 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:
334
467
335
468
``` bash
336
469
composer fix:style
0 commit comments