@@ -174,30 +174,6 @@ This Library supports Horizon, but in the config you have to inform Laravel to u
174
174
],
175
175
```
176
176
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
177
### Use your own RabbitMQJob class
202
178
203
179
Sometimes you have to work with messages published by another application.
@@ -288,7 +264,9 @@ class RabbitMQJob extends BaseJob
288
264
}
289
265
```
290
266
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
+
292
270
``` php
293
271
<?php
294
272
@@ -336,6 +314,93 @@ An example for the config:
336
314
],
337
315
```
338
316
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
+
339
404
### Default Queue
340
405
341
406
The 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
445
510
],
446
511
```
447
512
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
+
448
518
## Laravel Usage
449
519
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
452
522
documentation: http://laravel.com/docs/queues
453
523
454
524
## Lumen Usage
0 commit comments