wildpascal/remote-event-dispatcher

RemoteEventDispatcher for communicating between multiple systems.

dev-master 2016-05-05 11:49 UTC

This package is not auto-updated.

Last update: 2024-04-13 16:24:07 UTC


README

Build Status Total Downloads Latest Stable Version

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