@@ -149,8 +149,9 @@ by adding extra options.
149149```
150150
151151### 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 ` .
152+
153+ Starting with 8.0, this package supports [ Laravel Horizon] ( https://laravel.com/docs/horizon ) out of the box. Firstly,
154+ install Horizon and then set ` RABBITMQ_WORKER ` to ` horizon ` .
154155
155156Horizon is depending on events dispatched by the worker.
156157These events inform Horizon what was done with the message/job.
@@ -262,7 +263,9 @@ class RabbitMQJob extends BaseJob
262263}
263264```
264265
265- 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+
266269``` php
267270<?php
268271
@@ -310,6 +313,93 @@ An example for the config:
310313],
311314```
312315
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+
346+ class RabbitMQQueue extends BaseRabbitMQQueue
347+ {
348+ // ...
349+ }
350+ ```
351+
352+ ** For Example: A reconnect implementation.**
353+
354+ If you want to reconnect to RabbitMQ, if the connection is dead.
355+ You can override the publishing and the createChannel methods.
356+
357+ > Note: this is not best practice, it is an example.
358+
359+ ``` php
360+ <?php
361+
362+ namespace App\Queue;
363+
364+ use PhpAmqpLib\Exception\AMQPChannelClosedException;
365+ use PhpAmqpLib\Exception\AMQPConnectionClosedException;
366+ use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue as BaseRabbitMQQueue;
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+
313403### Default Queue
314404
315405The connection does use a default queue with value 'default', when no queue is provided by laravel.
@@ -419,10 +509,16 @@ If for some reason you don't want the connection lazy you can turn it off by set
419509],
420510```
421511
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+ > See: https://github.com/vyuldashev/laravel-queue-rabbitmq/issues/460#issuecomment-1469851667
517+
422518## Laravel Usage
423519
424- Once you completed the configuration you can use the Laravel Queue API. If you used other queue drivers you do not need to
425- 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
426522documentation: http://laravel.com/docs/queues
427523
428524## Lumen Usage
0 commit comments