farshidrezaei/larabbitmq

Laravel RabbitMq integration.

1.0.6 2022-05-07 06:56 UTC

This package is auto-updated.

Last update: 2024-04-07 11:12:40 UTC


README

Installation

composer

composer require farshidrezaei/larabbitmq

Larabbitmq environment

Set bellow config to .env file with your installed rabbitmq credential

LARABBITMQ_RABBIT_HOST=
LARABBITMQ_RABBIT_PORT=
LARABBITMQ_RABBIT_USERNAME=
LARABBITMQ_RABBIT_PASSWORD=

Config

Call bellow command to publish config file:

php artisan vendor:publish --provider="FarshidRezaei\Larabbitmq\Providers\LarabbitmqServiceProvider" --tag="config"

Usage:

publish:

You can use Larabbitmq Facade easily to publish messages on specified queue.

use FarshidRezaei\Larabbitmq\Facades\Larabbitmq;

Larabbitmq::publish( 'default_queue','default_exchange','simple_text_message' );

consume:

For consuming a queue you should create consume handler class and specified it for a queue in config/larabbitmq.php .

call bellow command to create new consume handler class:

php artisan larabbitmq:make-consume-handler ExampleConsumeHandler

Then ExampleConsumeHandler.php class will create in app/LarabbitmqConsumeHandlers. you must add this to config/larabbitmq.php like this:

// config/larabbitmq.php
  
  // ...
  
  'consume-handlers' => [
    'default_queue'=>App\LarabbitmqConsumeHandlers\ExampleConsumeHandler::class
  ]
    
  // ...

Now you can call bellow command to consume specifed queue:

php artisan larabbitmq:consume --queue=default_queue

License

The MIT License (MIT). Please see License File for more information.