wildpascal/ remote-event-dispatcher
用于多个系统之间通信的RemoteEventDispatcher。
dev-master
2016-05-05 11:49 UTC
Requires
- php: >=5.5.0
Requires (Dev)
- php-amqplib/php-amqplib: ~2.4
- phpunit/phpunit: 4.7.*
Suggests
- php-amqplib/php-amqplib: Allow sending log messages to an AMQP server using php-amqplib
This package is not auto-updated.
Last update: 2024-09-14 18:31:39 UTC
README
用于多个系统之间通信的RemoteEventDispatcher。
安装
使用composer安装包及其依赖
$ composer require wildpascal/remote-event-dispatcher
处理器
事件传输。可能的处理器
- AmqpHandler(通过实现Amqp协议的队列发送事件的处理器)
分发事件
要分发事件,您需要配置RemoteEventDispatcher。RemoteEventDispatcher需要一个处理器。
您可以分发所有继承自AbstractEvent的事件。
// Configuration for RabbitMQ or any other queue which is based on AMQP protocol $queueName = 'remote_event_dispatcher'; $config = [ 'host' => 'localhost', ]; $connection = new \PhpAmqpLib\Connection\AMQPStreamConnection('localhost', 5672, 'guest', 'guest'); $channel = $connection->channel(); // Configure AmqpHandler $handler = new \WP\RemoteEventDispatcher\Handler\Amqp\AmqpHandler($channel, $queueName); // Setup RemoteEventDispatcher with AmqpHandler $remoteEventDispatcher = new \WP\RemoteEventDispatcher\EventDispatcher\RemoteEventDispatcher($handler); $printHalloEvent = new \WP\RemoteEventDispatcher\Model\MutableEvent('printHalloEvent'); $printTestEvent = new \WP\RemoteEventDispatcher\Model\MutableEvent('printTestEvent'); $remoteEventDispatcher->dispatch($printHalloEvent); $remoteEventDispatcher->dispatch($printTestEvent);
监听事件
要监听事件,您需要配置RemoteEventListener。RemoteEventListener需要一个处理器和一个事件策略。
您还可以使用EventStrategyRegistry根据eventName注册不同的EventStrategies,以实现基于事件的逻辑。
// Configuration for RabbitMQ or any other queue which is based on AMQP protocol $queueName = 'remote_event_dispatcher'; $config = [ 'host' => 'localhost', ]; $connection = new \PhpAmqpLib\Connection\AMQPStreamConnection('localhost', 5672, 'guest', 'guest'); $channel = $connection->channel(); // Configure AmqpHandler $handler = new \WP\RemoteEventDispatcher\Handler\Amqp\AmqpHandler($channel, $queueName); // Setup your custom EventStrategy $eventStrategy = new YourCustomEventStrategy(); // Setup RemoteEventListener with AmqpHandler $remoteEventListener = new \WP\RemoteEventDispatcher\EventListener\RemoteEventListener($handler, $eventStrategy); $remoteEventListener->listen();
许可证
此包受MIT许可证的约束。请参阅包中的完整许可证。
Resources/meta/LICENSE