PHP code example of twn39 / rabbitmq-delay-message

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

    

twn39 / rabbitmq-delay-message example snippets


 Wang\RabbitMQ\RabbitMQServiceProvider::class

php artisan vendor:publish

$delayMessage = app(DelayedMessage::class);

$delayMessage->setExchange('delay-exchange');
$delayMessage->setQueue('delay-queue');

$delayMessage->publish([
    'name' => 'Tang',
    'age' => 22,
], 5000);

return 'success';


$delayMessage = app(DelayedMessage::class);

$delayMessage->setExchange('delay-exchange');
$delayMessage->setQueue('delay-queue');

$delayMessage->consume(function (AMQPMessage $message) {
    var_dump(json_decode($message->body, true));
});