mucts / laravel-amqp
AMQPMessage SDK for Laravel 8
9.1.0
2022-02-16 08:27 UTC
Requires
- php: ^8.1
- ext-json: ^8.1
- ext-mbstring: ^8.1
- ext-sockets: ^8.1
- laravel/framework: ^9.1
- php-amqplib/php-amqplib: ^3.1
README
Laravel AMQP
AMQPMessage SDK for Laravel 8
Installation
Server Requirements
you will need to make sure your server meets the following requirements:
php ^8.0
JSON PHP Extension
Sockets PHP Extension
MBString PHP Extension
php-amqplib/php-amqplib 3.0
laravel/framework ^8.41
Laravel Installation
composer require mucts/laravel-amqp
Usage
- AMQPMessage publisher
<?php use MuCTS\Laravel\AMQP\Facades\AMQP; use PhpAmqpLib\Exchange\AMQPExchangeType; // send message AMQP::connection('default') ->setExchange('test') ->setExchangeType(AMQPExchangeType::TOPIC) ->setQueue('test') ->publish('test');
- AMQPMessage consumer
use MuCTS\Laravel\AMQP\Commands\AMQPCommand; use PhpAmqpLib\Message\AMQPMessage; use Illuminate\Support\Facades\Log; use PhpAmqpLib\Exchange\AMQPExchangeType; class test extends AMQPCommand{ protected string $exchange = 'test'; protected string $queue = 'test'; protected string $exchangeType = AMQPExchangeType::TOPIC; protected string $consumerTag = 'consumer'; protected ?string $connectionName = 'default'; protected bool $autoAsk = false; protected function processMessage(AMQPMessage $message){ Log::info($message->getBody()); // message ask $message->ack(); // message nack $message->nack(true); } }
Configuration
If config/amqp.php
not exist, run below:
php artisan vendor:publish