AMQPMessage SDK for Laravel 8
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
composer require mucts/laravel-amqp
- 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);
}
}
If config/amqp.php
not exist, run below:
php artisan vendor:publish