wildpascal / remote-event-dispatcher
RemoteEventDispatcher for communicating between multiple systems.
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: 2025-02-01 20:31:58 UTC
README
RemoteEventDispatcher for communicating between multiple systems.
Installation
Require the bundle and its dependencies with composer:
$ composer require wildpascal/remote-event-dispatcher
Handler
Transport for Events. Possible Handlers:
- AmqpHandler (Handler to send Events via a queue which is implementing the Amqp protocol)
Dispatch Events
To dispatch events you have to configure the RemoteEventDispatcher. The RemoteEventDispatcher requires a Handler.
You can dispatch every event which extends the 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);
Listen for Events
To Listen for Events you have to configure the RemoteEventListener. The RemoteEventListener requires a Handler and a EventStrategy.
You also can use a EventStrategyRegistry to register different EventStrategies based on the eventName to implement a logic based on Events
// 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();
License
This bundle is under the MIT license. See the complete license in the bundle:
Resources/meta/LICENSE