PHP code example of mucts / laravel-amqp

1. Go to this page and download the library: Download mucts/laravel-amqp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mucts / laravel-amqp example snippets



use MuCTS\Laravel\AMQP\Facades\AMQP;
use PhpAmqpLib\Exchange\AMQPExchangeType;

// send message
AMQP::connection('default')
->setExchange('test')
->setExchangeType(AMQPExchangeType::TOPIC)
->setQueue('test')
->publish('test');


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);
    }
}

php artisan vendor:publish