mucts/laravel-amqp

AMQPMessage SDK for Laravel 8

9.1.0 2022-02-16 08:27 UTC

This package is auto-updated.

Last update: 2024-10-16 13:57:04 UTC


README

Build Status Code Intelligence Status Scrutinizer Code Quality Total Downloads Latest Stable Version License

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