@@ -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.
@@ -254,17 +262,143 @@ class RabbitMQJob extends BaseJob
254
262
}
255
263
```
256
264
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
+
257
396
## Laravel Usage
258
397
259
398
Once you completed the configuration you can use the Laravel Queue API. If you used other queue drivers you do not need to
260
399
change anything else. If you do not know how to use the Queue API, please refer to the official Laravel
261
400
documentation: http://laravel.com/docs/queues
262
401
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
-
268
402
## Lumen Usage
269
403
270
404
For 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.
287
421
Setup RabbitMQ using ` docker-compose ` :
288
422
289
423
``` bash
290
- docker- compose up -d rabbitmq
424
+ docker compose up -d
291
425
```
292
426
293
427
To run the test suite you can use the following commands:
@@ -304,7 +438,7 @@ composer test:unit
304
438
```
305
439
306
440
If 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:
308
442
309
443
``` bash
310
444
composer fix:style
0 commit comments