PHP code example of alive2212 / laravel-amqp

1. Go to this page and download the library: Download alive2212/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/ */

    

alive2212 / laravel-amqp example snippets


'providers' => [
    /// ... 
    Anik\Amqp\ServiceProviders\AmqpServiceProvider::class,
]

php artisan vendor:publish --provider="Anik\Amqp\ServiceProviders\AmqpServiceProvider"

$app->register(Anik\Amqp\ServiceProviders\AmqpServiceProvider::class);

'providers' => [
    /// ... 
    Anik\Amqp\ServiceProviders\AmqpServiceProvider::class,
]


// AmqpManager::publish($msg, $routing, $config);
app('amqp')->publish('Message to direct exchange', 'routing-key', [
    'exchange' => [
        'type'    => 'direct',
        'name'    => 'direct.exchange',
    ],
]);


use Anik\Amqp\ConsumableMessage;

// AmqpManager::consume($consumerHandler, $bindingKey, $config);
app('amqp')->consume(function (ConsumableMessage $message) {
    echo $message->getStream() . PHP_EOL;
    $message->getDeliveryInfo()->acknowledge();
}, 'routing-key', [
    'connection' => 'my-connection-name',
    'exchange'   => [
        'type'    => 'direct',
        'name'    => 'direct.exchange',
    ],
    'queue' => [
        'name'         => 'direct.exchange.queue',
        'declare'      => true,
        'exclusive'    => false,
    ],
    'qos' => [
        'enabled'            => true,
        'qos_prefetch_count' => 5,
    ],
]);