Looking to hire Laravel developers? Try LaraJobs

laravel-amqp maintained by mucts

Description
AMQPMessage SDK for Laravel 8
Author
Last update
2022/02/16 09:27 (dev-master)
License
Links
Downloads
21

Comments
comments powered by Disqus

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