PHP code example of johndev / hermes

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

    

johndev / hermes example snippets


Hermes\Providers\HermesServiceProvider::class,

'Hermes' => Hermes\Facades\Hermes::class,



use Hermes\Facades\Hermes;

$bindingKey = 'co.johndev.test';
$message = 'Test message';

Hermes::publish($bindingKey, $message);



use JohnDev\Hermes\Message;
use JohnDev\Hermes\Contracts\CarrierContract;

Hermes::consume(function(Message $message, CarrierContract $carrier) {
    dump($message->body());
    $message->ack();
    $carrier->finish();
});



use JohnDev\Hermes\Facades\Hermes;
use JohnDev\Hermes\Message;
use JohnDev\Hermes\Contracts\CarrierContract;

Hermes::queue('queue-name')->consume(function(Message $message, CarrierContract $carrier) {
    dump($message->body());
    $message->ack();
    $carrier->finish();
});



use JohnDev\Hermes\Facades\Hermes;
use JohnDev\Hermes\Message;
use JohnDev\Hermes\Contracts\CarrierContract;

$config = [
'consume' => [
        'tag' => 'custom-tag',
        'timeout' => 10,
    ]
];

Hermes::config($config)->consume(function(Message $message, CarrierContract $carrier) {
    dump($message->body());
    $message->ack();
    $carrier->finish();
});
shell
php artisan vendor:publish --provider="JohnDev\Hermes\Providers\HermesServiceProvider"