efabrica/hermes-extension

Extension for tomaj/hermes

1.2.0 2024-11-13 17:32 UTC

This package is auto-updated.

Last update: 2024-11-13 17:33:25 UTC


README

PHPStan level PHP static analysis Latest Stable Version Total Downloads

Extension for tomaj/hermes. It contains:

  • HermesWorker (symfony command)
  • Drivers:
    • RedisProxySetDriver (driver implementation using RedisProxy)
    • RedisProxySortedSetDriver
    • DummyDriver (for testing purposes)
  • Heartbeat functionality with drivers
    • RedisProxyStorage
    • MemoryStorage (for testing purposes)

Installation

composer require efabrica/hermes-extension

Setup

use Efabrica\HermesExtension\Driver\RedisProxySetDriver;
use Efabrica\HermesExtension\Heartbeat\RedisProxyStorage;
use RedisProxy\RedisProxy;
use Tomaj\Hermes\Dispatcher;
use Tomaj\Hermes\Handler\EchoHandler;
use Tomaj\Hermes\Shutdown\SharedFileShutdown;

$redisProxy = new RedisProxy(/*...*/);

// Register driver
$driver = new RedisProxySetDriver($redisProxy, 'hermes');

// Optionally register shutdown and / or heartbeat
$driver->setShutdown(new SharedFileShutdown('/tmp/hermes_shared_file'));
$driver->setHeartbeat(new RedisProxyStorage($redisProxy, 'hermes_heartbeat'));

// Create Dispatcher
$dispatcher = new Dispatcher($driver);

// Register handlers
$dispatcher->registerHandler('event_type', new EchoHandler());

Register hermes worker to symfony console application:

// file: bin/command

use Efabrica\HermesExtension\Command\HermesWorker;
use Symfony\Component\Console\Application;


$application = new Application();
$application->add(new HermesWorker($dispatcher));
$application->run();

Run command:

php bin/command hermes:worker