dafiti/messagebus

There is no license information available for the latest version (2.2.1) of this package.

messagebus

This package's canonical repository appears to be gone and the package has been frozen as a result.

2.2.1 2017-10-24 15:43 UTC

README

Send event messages using AWS SNS

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Instalation

Add:

"dafiti/messagebus": "dev-master"

To your composer.json

or Run:

composer require dafiti/messagebus

Usage

<?php

use Aws\Kinesis\KinesisClient;
use Dafiti\MessageBus\Config;
use Dafiti\MessageBus\Dispatcher\Adapter\Kinesis;
use Dafiti\MessageBus\Dispatcher\Dispatcher;
use Dafiti\MessageBus\Entity\Order\OrderEntity;
use Dafiti\MessageBus\Events\EventCollection;
use Dafiti\MessageBus\Events\Order\CreateOrder;
use Dafiti\MessageBus\MessageBus;

require __DIR__ . "/../vendor/autoload.php";

// Create library configuration
$config = new Config(Config::ENV_LOCAL, 'fake-steeam-name', 'fake-sender', 'partition-key');

// Initialize dispatcher adapter
$kinesisClient = new KinesisClient([
    'profile' => 'default',
    'region' => 'us-east-1',
    'version' => 'latest',
]);
$adapter = new Kinesis($kinesisClient, $config);

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

// Create the main object
$messageBus = new MessageBus($dispatcher, $config);

// Configure the event to be dispatched
$order = new OrderEntity(...);
$event = new CreateOrder($order);

$messageBus->dispatch(new EventCollection([$event]));

This will send a message through the configurated adapter with the payload from the event that you created.