@@ -151,8 +151,7 @@ by adding extra options.
151
151
### Horizon support
152
152
153
153
Starting with 8.0, this package supports [ Laravel Horizon] ( https://laravel.com/docs/horizon ) out of the box. Firstly,
154
- install
155
- Horizon and then set ` RABBITMQ_WORKER ` to ` horizon ` .
154
+ install Horizon and then set ` RABBITMQ_WORKER ` to ` horizon ` .
156
155
157
156
Horizon is depending on events dispatched by the worker.
158
157
These events inform Horizon what was done with the message/job.
@@ -174,30 +173,6 @@ This Library supports Horizon, but in the config you have to inform Laravel to u
174
173
],
175
174
```
176
175
177
- ### Octane support
178
-
179
- Starting with 13.3.0, this package supports [ Laravel Octane] ( https://laravel.com/docs/octane ) out of the box. Firstly,
180
- install
181
- Octane and then set ` RABBITMQ_WORKER ` to ` octane ` .
182
-
183
- This Library supports Octane, but in the config you have to inform Laravel to use the QueueApi compatible with octane.
184
-
185
- > Note: don't forget to warm 'rabbitmq' connection in the octane config.
186
- ``` php
187
- 'connections' => [
188
- // ...
189
-
190
- 'rabbitmq' => [
191
- // ...
192
-
193
- /* Set to "octane" if you wish to use Laravel Octane. */
194
- 'worker' => env('RABBITMQ_WORKER', 'default'),
195
- ],
196
-
197
- // ...
198
- ],
199
- ```
200
-
201
176
### Use your own RabbitMQJob class
202
177
203
178
Sometimes you have to work with messages published by another application.
@@ -288,7 +263,9 @@ class RabbitMQJob extends BaseJob
288
263
}
289
264
```
290
265
291
- If you want to handle raw message, not in JSON format or without 'job' key in JSON, you should add stub for ` getName ` method:
266
+ If you want to handle raw message, not in JSON format or without 'job' key in JSON,
267
+ you should add stub for ` getName ` method:
268
+
292
269
``` php
293
270
<?php
294
271
@@ -336,6 +313,93 @@ An example for the config:
336
313
],
337
314
```
338
315
316
+ ### Use your own Worker class
317
+
318
+ If you want to use your own ` RabbitMQQueue::class ` this is possible by
319
+ extending ` VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue ` .
320
+ and inform laravel to use your class by setting ` RABBITMQ_WORKER ` to ` \App\Queue\RabbitMQQueue::class ` .
321
+
322
+ > Note: Worker classes ** must** extend ` VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue `
323
+
324
+ ``` php
325
+ 'connections' => [
326
+ // ...
327
+
328
+ 'rabbitmq' => [
329
+ // ...
330
+
331
+ /* Set to a class if you wish to use your own. */
332
+ 'worker' => \App\Queue\RabbitMQQueue::class,
333
+ ],
334
+
335
+ // ...
336
+ ],
337
+ ```
338
+
339
+ ``` php
340
+ <?php
341
+
342
+ namespace App\Queue;
343
+
344
+ use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue as BaseRabbitMQQueue;
345
+ use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\ReconnectTrait;
346
+
347
+ class RabbitMQQueue extends BaseRabbitMQQueue
348
+ {
349
+ // ...
350
+ }
351
+ ```
352
+
353
+ ** For Example: A reconnect implementation.**
354
+
355
+ If you want to reconnect to RabbitMQ, if the connection is dead.
356
+ You can override the publishing and the createChannel methods.
357
+
358
+ > Note: this is not best practice, it is an example.
359
+
360
+ ``` php
361
+ <?php
362
+
363
+ namespace App\Queue;
364
+
365
+ use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue as BaseRabbitMQQueue;
366
+ use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\ReconnectTrait;
367
+
368
+ class RabbitMQQueue extends BaseRabbitMQQueue
369
+ {
370
+
371
+ protected function publishBasic($msg, $exchange = '', $destination = '', $mandatory = false, $immediate = false, $ticket = null): void
372
+ {
373
+ try {
374
+ parent::publishBasic($msg, $exchange, $destination, $mandatory, $immediate, $ticket);
375
+ } catch (AMQPConnectionClosedException|AMQPChannelClosedException) {
376
+ $this->reconnect();
377
+ parent::publishBasic($msg, $exchange, $destination, $mandatory, $immediate, $ticket);
378
+ }
379
+ }
380
+
381
+ protected function publishBatch($jobs, $data = '', $queue = null): void
382
+ {
383
+ try {
384
+ parent::publishBatch($jobs, $data, $queue);
385
+ } catch (AMQPConnectionClosedException|AMQPChannelClosedException) {
386
+ $this->reconnect();
387
+ parent::publishBatch($jobs, $data, $queue);
388
+ }
389
+ }
390
+
391
+ protected function createChannel(): AMQPChannel
392
+ {
393
+ try {
394
+ return parent::createChannel();
395
+ } catch (AMQPConnectionClosedException) {
396
+ $this->reconnect();
397
+ return parent::createChannel();
398
+ }
399
+ }
400
+ }
401
+ ```
402
+
339
403
### Default Queue
340
404
341
405
The connection does use a default queue with value 'default', when no queue is provided by laravel.
@@ -445,10 +509,15 @@ If for some reason you don't want the connection lazy you can turn it off by set
445
509
],
446
510
```
447
511
512
+ ### Octane support
513
+
514
+ Starting with 13.3.0, this package supports [ Laravel Octane] ( https://laravel.com/docs/octane ) out of the box.
515
+ Firstly, install Octane and don't forget to warm 'rabbitmq' connection in the octane config.
516
+
448
517
## Laravel Usage
449
518
450
- Once you completed the configuration you can use the Laravel Queue API. If you used other queue drivers you do not need to
451
- change anything else. If you do not know how to use the Queue API, please refer to the official Laravel
519
+ Once you completed the configuration you can use the Laravel Queue API. If you used other queue drivers you do not
520
+ need to change anything else. If you do not know how to use the Queue API, please refer to the official Laravel
452
521
documentation: http://laravel.com/docs/queues
453
522
454
523
## Lumen Usage
0 commit comments