efabrica / hermes-extension

tomaj/hermes 扩展

1.1.0 2024-04-17 10:39 UTC

This package is auto-updated.

Last update: 2024-08-23 09:38:18 UTC


README

PHPStan level PHP static analysis Latest Stable Version Total Downloads

为 tomaj/hermes 提供扩展。它包含

  • HermesWorker(symfony 命令)
  • 驱动程序
    • RedisProxySetDriver(使用 RedisProxy 实现的驱动程序)
    • RedisProxySortedSetDriver
    • DummyDriver(测试用途)
  • 与驱动程序的 heartbeat 功能
    • RedisProxyStorage
    • MemoryStorage(测试用途)

安装

composer require efabrica/hermes-extension

设置

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

将 hermes worker 注册到 symfony 控制台应用程序

// file: bin/command

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


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

运行命令

php bin/command hermes:worker