Skip to content

Latest commit

 

History

History
142 lines (91 loc) · 4.68 KB

readme.md

File metadata and controls

142 lines (91 loc) · 4.68 KB

Laravel Broadway

SensioLabsInsight Scrutinizer Code Quality Latest Stable Version Total Downloads Latest Unstable Version License

Laravel Broadway is an adapter for the Broadway package.

It binds all needed interfaces for Broadway.

For reference, I've built a demo laravel application that uses this package and some event sourcing techniques.

Installation

Install via composer

composer require nwidart/laravel-broadway=~0.1

Service Providers

To finish the installation you need to add the service providers.

You have a choice here, you can either use the main Service Provider which will load the following:

Or choose to use only the Service providers you need. Don't know what you need ? Use the Global Service Provider provided.

Global Service Provider

   'Nwidart\LaravelBroadway\LaravelBroadwayServiceProvider'

Separate Service Providers

  • CommandBus

    'Nwidart\LaravelBroadway\Broadway\CommandServiceProvider'
  • EventBus

    'Nwidart\LaravelBroadway\Broadway\EventServiceProvider'
  • Serializers

    'Nwidart\LaravelBroadway\Broadway\SerializersServiceProvider'
  • EventStorage

    'Nwidart\LaravelBroadway\Broadway\EventStorageServiceProvider'
  • ElasticSearch

    'Nwidart\LaravelBroadway\Broadway\ElasticSearchServiceProvider'
  • Support

    'Nwidart\LaravelBroadway\Broadway\SupportServiceProvider'

(optional) Publish configuration

php artisan config:publish nwidart/laravel-broadway

Configuration

Event Store

To create the event store you can call the following command:

php artisan broadway:event-store:migrate table_name

In the configuration file, you can choose which driver to use as an event store.

'event-store' => [
    'table' => 'event_store',
    'driver' => 'dbal'
],

Read Model

To set a read model in your application you first need to set the wanted read model in the package configuration.

Once that's done you can bind a ReadModelRepository like so:

$this->app->bind('Modules\Parts\Repositories\ReadModelPartRepository', function ($app) {
    $serializer = $app['Broadway\Serializer\SerializerInterface'];
    return new ElasticSearchReadModelPartRepository($app['Elasticsearch'], $serializer);
});

For an In Memory read model as an example:

$this->app->bind('Modules\Parts\Repositories\ReadModelPartRepository', function ($app) {
    $serializer = $app['Broadway\Serializer\SerializerInterface'];
    return new InMemoryReadModelPartRepository($app['Inmemory'], $serializer);
});

See the demo laravel application and specifically the Service Provider for an working example.