@@ -174,30 +174,6 @@ This Library supports Horizon, but in the config you have to inform Laravel to u
174174],
175175```
176176
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-
201177### Use your own RabbitMQJob class
202178
203179Sometimes you have to work with messages published by another application.
@@ -288,7 +264,9 @@ class RabbitMQJob extends BaseJob
288264}
289265```
290266
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:
267+ If you want to handle raw message, not in JSON format or without 'job' key in JSON, you should add stub for ` getName `
268+ method:
269+
292270``` php
293271<?php
294272
@@ -336,6 +314,93 @@ An example for the config:
336314],
337315```
338316
317+ ### Use your own Worker class
318+
319+ If you want to use your own ` RabbitMQQueue::class ` this is possible by
320+ extending ` VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue ` .
321+ and inform laravel to use your class by setting ` RABBITMQ_WORKER ` to ` \App\Queue\RabbitMQQueue::class ` .
322+
323+ > Note: Worker classes ** must** extend `` VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue ``
324+
325+ ``` php
326+ 'connections' => [
327+ // ...
328+
329+ 'rabbitmq' => [
330+ // ...
331+
332+ /* Set to a class if you wish to use your own. */
333+ 'worker' => \App\Queue\RabbitMQQueue::class,
334+ ],
335+
336+ // ...
337+ ],
338+ ```
339+
340+ ``` php
341+ <?php
342+
343+ namespace App\Queue;
344+
345+ use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue as BaseRabbitMQQueue;
346+ use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\ReconnectTrait;
347+
348+ class RabbitMQQueue extends BaseRabbitMQQueue
349+ {
350+ // ...
351+ }
352+ ```
353+
354+ ** For Example: A reconnect implementation.**
355+
356+ If you want to reconnect to RabbitMQ, if the connection is dead.
357+ You can override the publishing and the createChannel methods.
358+
359+ > Note: this is not best practice, it is an example.
360+
361+ ``` php
362+ <?php
363+
364+ namespace App\Queue;
365+
366+ use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue as BaseRabbitMQQueue;
367+ use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\ReconnectTrait;
368+
369+ class RabbitMQQueue extends BaseRabbitMQQueue
370+ {
371+
372+ protected function publishBasic($msg, $exchange = '', $destination = '', $mandatory = false, $immediate = false, $ticket = null): void
373+ {
374+ try {
375+ parent::publishBasic($msg, $exchange, $destination, $mandatory, $immediate, $ticket);
376+ } catch (AMQPConnectionClosedException|AMQPChannelClosedException) {
377+ $this->reconnect();
378+ parent::publishBasic($msg, $exchange, $destination, $mandatory, $immediate, $ticket);
379+ }
380+ }
381+
382+ protected function publishBatch($jobs, $data = '', $queue = null): void
383+ {
384+ try {
385+ parent::publishBatch($jobs, $data, $queue);
386+ } catch (AMQPConnectionClosedException|AMQPChannelClosedException) {
387+ $this->reconnect();
388+ parent::publishBatch($jobs, $data, $queue);
389+ }
390+ }
391+
392+ protected function createChannel(): AMQPChannel
393+ {
394+ try {
395+ return parent::createChannel();
396+ } catch (AMQPConnectionClosedException) {
397+ $this->reconnect();
398+ return parent::createChannel();
399+ }
400+ }
401+ }
402+ ```
403+
339404### Default Queue
340405
341406The connection does use a default queue with value 'default', when no queue is provided by laravel.
@@ -445,10 +510,15 @@ If for some reason you don't want the connection lazy you can turn it off by set
445510],
446511```
447512
513+ ### Octane support
514+
515+ Starting with 13.3.0, this package supports [ Laravel Octane] ( https://laravel.com/docs/octane ) out of the box.
516+ Firstly, install Octane and don't forget to warm 'rabbitmq' connection in the octane config.
517+
448518## Laravel Usage
449519
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
520+ Once you completed the configuration you can use the Laravel Queue API. If you used other queue drivers you do not
521+ need to change anything else. If you do not know how to use the Queue API, please refer to the official Laravel
452522documentation: http://laravel.com/docs/queues
453523
454524## Lumen Usage
0 commit comments