Coder Social home page Coder Social logo

laravel-broadway's Introduction

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.

Laravel 5 compatible package

Laravel version Package version
~4.2 ~0.2
~5.0 ~0.3
~5.1+ ~2.0

Installation

Install via composer

composer require nwidart/laravel-broadway=~1.0

Service Providers

Laravel 5.5 (Auto discovery)

If you are using Laravel 5.5, this package provides auto discovery, meaning you can start coding โ€“ the Global Service Provider is already added. In case you need just some Service Providers, please add the following section to your applications composer.json:

 "extra": {
    "laravel": {
      "dont-discover": [
        "nWidart/Laravel-broadway"
      ]
    }
  }

Laravel 5.4

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::class

Separate Service Providers

  • CommandBus

    Nwidart\LaravelBroadway\Broadway\CommandServiceProvider::class
  • EventBus

    Nwidart\LaravelBroadway\Broadway\EventServiceProvider::class
  • Serializers

    Nwidart\LaravelBroadway\Broadway\SerializersServiceProvider::class
  • EventStorage

    Nwidart\LaravelBroadway\Broadway\EventStorageServiceProvider::class
  • ReadModel

    Nwidart\LaravelBroadway\Broadway\ReadModelServiceProvider::class
  • MetadataEnricher

    Nwidart\LaravelBroadway\Broadway\MetadataEnricherServiceProvider::class
  • Support

    Nwidart\LaravelBroadway\Broadway\SupportServiceProvider::class

(Optional) Publish configuration file and migration

php artisan vendor:publish

This will publish a config/broadway.php file and a database/migrations/create_event_store_table.php file.

(Optional) Run migration

Last step, run the migration that was published in the last step to create the event_store table.

If you haven't published the vendor files, you can use the command explained below:

php artisan broadway:event-store:migrate table_name

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 and which connection to use.

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

Once done, you can bind your EventStoreRepositories in a Service Provider like so:

$this->app->bind(\Modules\Parts\Repositories\EventStorePartRepository::class, function ($app) {
    $eventStore = $app[\Broadway\EventStore\EventStore::class];
    $eventBus = $app[\Broadway\EventHandling\EventBus::class];
    return new MysqlEventStorePartRepository($eventStore, $eventBus);
});

For an in memory Event Store, all you need to do is change the driver in the configuration file and probably add a new event store repository implementation with an adequate name.

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 your ReadModelRepositories in a Service Provider like so:

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

For an In Memory read model as an example:

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

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

Registering subscribers

Command handlers

To let broadway know which handlers are available you need to bind in the Laravel IoC container a key named broadway.command-subscribers as a singleton.

It's important to know Command Handlers classes in broadway need to get a Event Store repository injected.

Now just pass either an array of command handlers to the laravelbroadway.command.registry key out the IoC Container or just one class, like so:

$partCommandHandler = new PartCommandHandler($this->app[\Modules\Parts\Repositories\EventStorePartRepository::class]);
$someOtherCommandHandler = new SomeOtherCommandHandler($this->app[\Modules\Things\Repositories\EventStoreSomeRepository::class]);

$this->app['laravelbroadway.command.registry']->subscribe([
    $partCommandHandler,
    $someOtherCommandHandler
]);

// OR

$this->app['laravelbroadway.command.registry']->subscribe($partCommandHandler);
$this->app['laravelbroadway.command.registry']->subscribe($someOtherCommandHandler);

Event subscribers

This is pretty much the same as the command handlers, except that the event subscriber (or listener) needs an Read Model repository.

Example:

$partsThatWereManfacturedProjector = new PartsThatWereManufacturedProjector($this->app[\Modules\Parts\Repositories\ReadModelPartRepository::class]);
$someOtherProjector = new SomeOtherProjector($this->app[\Modules\Things\Repositories\ReadModelSomeRepository::class]);

$this->app['laravelbroadway.event.registry']->subscribe([
    $partsThatWereManfacturedProjector,
    $someOtherProjector
]);

// OR

$this->app['laravelbroadway.event.registry']->subscribe($partsThatWereManfacturedProjector);
$this->app['laravelbroadway.event.registry']->subscribe($someOtherProjector);

Metadata Enricher

Broadways event store table comes with a field called "metadata". Here we can store all kind of stuff which should be saved together with the particular event, but which is does not fit to the domain aka the payload.

For example you like to store the ID of the current logged-in user or the IP or ...

Broadway uses Decorators to manipulate the event stream. A decorator consumes one or more Enrichers, which provide the actual data (user ID, IP). Right before saving the event to the stream, the decorator will loop through the registered enrichers and apply the data.

The following example assumes you added the global ServiceProvider of this package or at least the Nwidart\LaravelBroadway\Broadway\MetadataEnricherServiceProvider.

First we create the enricher. In this example lets assume we are interested in the logged-in user. The enricher will add the user ID to the metadata and returns the modified metadata object. However, in some cases โ€“ like in Unit Tests - there is no logged-in user available. To tackle this, the user ID can injected via constructor.

// CreatorEnricher.php

class CreatorEnricher implements MetadataEnricher
{
    /** @var int $creatorId */
    private $creatorId;


    /**
     * The constructor
     *
     * @param int $creatorId
     */
    public function __construct($creatorId = null)
    {
        $this->creatorId = $creatorId;
    }


    /**
     * @param Metadata $metadata
     * @return Metadata
     */
    public function enrich(Metadata $metadata)
    {
        if ($this->creatorId !== null) {
            $id = $this->creatorId;
        } else {
            $id = Auth::user()->id;
        }

        return $metadata->merge(Metadata::kv('createorId', $id));
    }
}

Second you need to register the Enricher to the decorator and pass the decorator to your repository

// YourServiceProvider.php

/**
 * Register the Metadata enrichers
 */
private function registerEnrichers()
{
    $enricher = new CreatorEnricher();
    $this->app['laravelbroadway.enricher.registry']->subscribe([$enricher]);
}

$this->app->bind(\Modules\Parts\Repositories\EventStorePartRepository::class, function ($app) {
    $eventStore = $app[\Broadway\EventStore\EventStore::class];
    $eventBus = $app[\Broadway\EventHandling\EventBus::class];
    
    $this->registerEnrichers();
    
    return new MysqlEventStorePartRepository($eventStore, $eventBus, $app[Connection::class], [$app[EventStreamDecorator::class]);
});

To retrieve the metadata you need to pass the DomainMessage as the 2nd parameter to an apply*-method in your projector.

// PartsThatWhereCreatedProjector.php

public function applyPartWasRenamedEvent(PartWasRenamedEvent $event, DomainMessage $domainMessage)
{
	$metaData = $domainMessage->getMetadata()->serialize();
	$creator = User::find($metaData['creatorId']);    
	
	// Do something with the user
}

All the rest are conventions from the Broadway package.


laravel-broadway's People

Contributors

alessandrominoccheri avatar big-shark avatar konafets avatar lavatoaster avatar moleculezz avatar noeldavies avatar nwidart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-broadway's Issues

Interface Segregation

Hi Nicolas, wonder if you can help me with my query. I would like to use your package on a new ES domain but I would like to be able to segregate this using interface so that my model does not specifically depend on any classes outside of itself. Is there any way I can do this without developing a package like yours as I would like to use your package.

Basically I want to use interfaces within the model such as:

class GenerateLeadCommandHandler implements MyModelCommandHandlerInterface

interface MyModelCommandHandlerInterface implements YourCommandHandlerInterface

Is this possible or will I need to implement the Broadway ones as you do in your package?

Installation on Laravel Spark fails

Hello,

I'm trying to install your repository, however I get an error I cannot resolve. Would you be so kind to assist?

vagrant@homestead:~/Projects/v1$ composer require nwidart/laravel-broadway=~0.3
You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: remove symfony/console v3.0.5
    - Conclusion: don't install symfony/console v3.0.5
    - rhumsaa/uuid 2.6.0 requires symfony/console ~2.4 -> satisfiable by symfony/console[v2.4.0, v2.4.1, v2.4.10, v2.4.2, v2.4.3, v2.4.4, v2.4.5, v2.4.6, v2.4.7, v2.4.8, v2.4.9, v2.5.0, v2.5.1, v2.5.10, v2.5.11, v2.5.12, v2.5.2, v2.5.3, v2.5.4, v2.5.5, v2.5.6, v2.5.7, v2.5.8, v2.5.9, v2.6.0, v2.6.1, v2.6.10, v2.6.11, v2.6.12, v2.6.13, v2.6.2, v2.6.3, v2.6.4, v2.6.5, v2.6.6, v2.6.7, v2.6.8, v2.6.9, v2.7.0, v2.7.1, v2.7.10, v2.7.11, v2.7.12, v2.7.2, v2.7.3, v2.7.4, v2.7.5, v2.7.6, v2.7.7, v2.7.8, v2.7.9, v2.8.0, v2.8.1, v2.8.2, v2.8.3, v2.8.4, v2.8.5].
    - rhumsaa/uuid 2.6.1 requires symfony/console ~2.4 -> satisfiable by symfony/console[v2.4.0, v2.4.1, v2.4.10, v2.4.2, v2.4.3, v2.4.4, v2.4.5, v2.4.6, v2.4.7, v2.4.8, v2.4.9, v2.5.0, v2.5.1, v2.5.10, v2.5.11, v2.5.12, v2.5.2, v2.5.3, v2.5.4, v2.5.5, v2.5.6, v2.5.7, v2.5.8, v2.5.9, v2.6.0, v2.6.1, v2.6.10, v2.6.11, v2.6.12, v2.6.13, v2.6.2, v2.6.3, v2.6.4, v2.6.5, v2.6.6, v2.6.7, v2.6.8, v2.6.9, v2.7.0, v2.7.1, v2.7.10, v2.7.11, v2.7.12, v2.7.2, v2.7.3, v2.7.4, v2.7.5, v2.7.6, v2.7.7, v2.7.8, v2.7.9, v2.8.0, v2.8.1, v2.8.2, v2.8.3, v2.8.4, v2.8.5].
    - rhumsaa/uuid 2.7.0 requires symfony/console ~2.4 -> satisfiable by symfony/console[v2.4.0, v2.4.1, v2.4.10, v2.4.2, v2.4.3, v2.4.4, v2.4.5, v2.4.6, v2.4.7, v2.4.8, v2.4.9, v2.5.0, v2.5.1, v2.5.10, v2.5.11, v2.5.12, v2.5.2, v2.5.3, v2.5.4, v2.5.5, v2.5.6, v2.5.7, v2.5.8, v2.5.9, v2.6.0, v2.6.1, v2.6.10, v2.6.11, v2.6.12, v2.6.13, v2.6.2, v2.6.3, v2.6.4, v2.6.5, v2.6.6, v2.6.7, v2.6.8, v2.6.9, v2.7.0, v2.7.1, v2.7.10, v2.7.11, v2.7.12, v2.7.2, v2.7.3, v2.7.4, v2.7.5, v2.7.6, v2.7.7, v2.7.8, v2.7.9, v2.8.0, v2.8.1, v2.8.2, v2.8.3, v2.8.4, v2.8.5].
    - ramsey/uuid 2.6.0 requires symfony/console ~2.4 -> satisfiable by symfony/console[v2.4.0, v2.4.1, v2.4.10, v2.4.2, v2.4.3, v2.4.4, v2.4.5, v2.4.6, v2.4.7, v2.4.8, v2.4.9, v2.5.0, v2.5.1, v2.5.10, v2.5.11, v2.5.12, v2.5.2, v2.5.3, v2.5.4, v2.5.5, v2.5.6, v2.5.7, v2.5.8, v2.5.9, v2.6.0, v2.6.1, v2.6.10, v2.6.11, v2.6.12, v2.6.13, v2.6.2, v2.6.3, v2.6.4, v2.6.5, v2.6.6, v2.6.7, v2.6.8, v2.6.9, v2.7.0, v2.7.1, v2.7.10, v2.7.11, v2.7.12, v2.7.2, v2.7.3, v2.7.4, v2.7.5, v2.7.6, v2.7.7, v2.7.8, v2.7.9, v2.8.0, v2.8.1, v2.8.2, v2.8.3, v2.8.4, v2.8.5].
    - ramsey/uuid 2.6.1 requires symfony/console ~2.4 -> satisfiable by symfony/console[v2.4.0, v2.4.1, v2.4.10, v2.4.2, v2.4.3, v2.4.4, v2.4.5, v2.4.6, v2.4.7, v2.4.8, v2.4.9, v2.5.0, v2.5.1, v2.5.10, v2.5.11, v2.5.12, v2.5.2, v2.5.3, v2.5.4, v2.5.5, v2.5.6, v2.5.7, v2.5.8, v2.5.9, v2.6.0, v2.6.1, v2.6.10, v2.6.11, v2.6.12, v2.6.13, v2.6.2, v2.6.3, v2.6.4, v2.6.5, v2.6.6, v2.6.7, v2.6.8, v2.6.9, v2.7.0, v2.7.1, v2.7.10, v2.7.11, v2.7.12, v2.7.2, v2.7.3, v2.7.4, v2.7.5, v2.7.6, v2.7.7, v2.7.8, v2.7.9, v2.8.0, v2.8.1, v2.8.2, v2.8.3, v2.8.4, v2.8.5].
    - ramsey/uuid 2.7.0 requires symfony/console ~2.4 -> satisfiable by symfony/console[v2.4.0, v2.4.1, v2.4.10, v2.4.2, v2.4.3, v2.4.4, v2.4.5, v2.4.6, v2.4.7, v2.4.8, v2.4.9, v2.5.0, v2.5.1, v2.5.10, v2.5.11, v2.5.12, v2.5.2, v2.5.3, v2.5.4, v2.5.5, v2.5.6, v2.5.7, v2.5.8, v2.5.9, v2.6.0, v2.6.1, v2.6.10, v2.6.11, v2.6.12, v2.6.13, v2.6.2, v2.6.3, v2.6.4, v2.6.5, v2.6.6, v2.6.7, v2.6.8, v2.6.9, v2.7.0, v2.7.1, v2.7.10, v2.7.11, v2.7.12, v2.7.2, v2.7.3, v2.7.4, v2.7.5, v2.7.6, v2.7.7, v2.7.8, v2.7.9, v2.8.0, v2.8.1, v2.8.2, v2.8.3, v2.8.4, v2.8.5].
    - Can only install one of: symfony/console[v2.4.10, v3.0.5].
    - Can only install one of: symfony/console[v2.4.2, v3.0.5].
    - Can only install one of: symfony/console[v2.4.3, v3.0.5].
    - Can only install one of: symfony/console[v2.4.4, v3.0.5].
    - Can only install one of: symfony/console[v2.4.5, v3.0.5].
    - Can only install one of: symfony/console[v2.4.6, v3.0.5].
    - Can only install one of: symfony/console[v2.4.7, v3.0.5].
    - Can only install one of: symfony/console[v2.4.8, v3.0.5].
    - Can only install one of: symfony/console[v2.4.9, v3.0.5].
    - Can only install one of: symfony/console[v2.5.0, v3.0.5].
    - Can only install one of: symfony/console[v2.5.1, v3.0.5].
    - Can only install one of: symfony/console[v2.5.10, v3.0.5].
    - Can only install one of: symfony/console[v2.5.11, v3.0.5].
    - Can only install one of: symfony/console[v2.5.12, v3.0.5].
    - Can only install one of: symfony/console[v2.5.2, v3.0.5].
    - Can only install one of: symfony/console[v2.5.3, v3.0.5].
    - Can only install one of: symfony/console[v2.5.4, v3.0.5].
    - Can only install one of: symfony/console[v2.5.5, v3.0.5].
    - Can only install one of: symfony/console[v2.5.6, v3.0.5].
    - Can only install one of: symfony/console[v2.5.7, v3.0.5].
    - Can only install one of: symfony/console[v2.5.8, v3.0.5].
    - Can only install one of: symfony/console[v2.5.9, v3.0.5].
    - Can only install one of: symfony/console[v2.6.0, v3.0.5].
    - Can only install one of: symfony/console[v2.6.1, v3.0.5].
    - Can only install one of: symfony/console[v2.6.10, v3.0.5].
    - Can only install one of: symfony/console[v2.6.11, v3.0.5].
    - Can only install one of: symfony/console[v2.6.12, v3.0.5].
    - Can only install one of: symfony/console[v2.6.13, v3.0.5].
    - Can only install one of: symfony/console[v2.6.2, v3.0.5].
    - Can only install one of: symfony/console[v2.6.3, v3.0.5].
    - Can only install one of: symfony/console[v2.6.4, v3.0.5].
    - Can only install one of: symfony/console[v2.6.5, v3.0.5].
    - Can only install one of: symfony/console[v2.6.6, v3.0.5].
    - Can only install one of: symfony/console[v2.6.7, v3.0.5].
    - Can only install one of: symfony/console[v2.6.8, v3.0.5].
    - Can only install one of: symfony/console[v2.6.9, v3.0.5].
    - Can only install one of: symfony/console[v2.7.0, v3.0.5].
    - Can only install one of: symfony/console[v2.7.1, v3.0.5].
    - Can only install one of: symfony/console[v2.7.10, v3.0.5].
    - Can only install one of: symfony/console[v2.7.11, v3.0.5].
    - Can only install one of: symfony/console[v2.7.12, v3.0.5].
    - Can only install one of: symfony/console[v2.7.2, v3.0.5].
    - Can only install one of: symfony/console[v2.7.3, v3.0.5].
    - Can only install one of: symfony/console[v2.7.4, v3.0.5].
    - Can only install one of: symfony/console[v2.7.5, v3.0.5].
    - Can only install one of: symfony/console[v2.7.6, v3.0.5].
    - Can only install one of: symfony/console[v2.7.7, v3.0.5].
    - Can only install one of: symfony/console[v2.7.8, v3.0.5].
    - Can only install one of: symfony/console[v2.7.9, v3.0.5].
    - Can only install one of: symfony/console[v2.8.0, v3.0.5].
    - Can only install one of: symfony/console[v2.8.1, v3.0.5].
    - Can only install one of: symfony/console[v2.8.2, v3.0.5].
    - Can only install one of: symfony/console[v2.8.3, v3.0.5].
    - Can only install one of: symfony/console[v2.8.4, v3.0.5].
    - Can only install one of: symfony/console[v2.8.5, v3.0.5].
    - Can only install one of: symfony/console[v2.4.0, v3.0.5].
    - Can only install one of: symfony/console[v2.4.1, v3.0.5].
    - Installation request for symfony/console (locked at v3.0.5) -> satisfiable by symfony/console[v3.0.5].
    - Installation request for nwidart/laravel-broadway ~0.3 -> satisfiable by nwidart/laravel-broadway[0.3.0].
    - Conclusion: don't install ramsey/uuid 3.4.1|install ramsey/uuid 2.6.0|install ramsey/uuid 2.6.1|install ramsey/uuid 2.7.0|install rhumsaa/uuid 2.6.0|install rhumsaa/uuid 2.6.1|install rhumsaa/uuid 2.7.0
    - Conclusion: remove ramsey/uuid 3.4.1|install ramsey/uuid 2.6.0|install ramsey/uuid 2.6.1|install ramsey/uuid 2.7.0|install rhumsaa/uuid 2.6.0|install rhumsaa/uuid 2.6.1|install rhumsaa/uuid 2.7.0
    - nwidart/laravel-broadway 0.3.0 requires broadway/broadway ~0.4 -> satisfiable by broadway/broadway[0.4.0, 0.5.0, 0.5.1, 0.5.2, 0.6.0, 0.7.0, 0.7.1, 0.8.0, 0.9.0].
    - broadway/broadway 0.6.0 requires ramsey/uuid ~2.4 -> satisfiable by ramsey/uuid[2.4.0, 2.5.0, 2.6.0, 2.6.1, 2.7.0, 2.7.1, 2.7.2, 2.7.3, 2.7.4, 2.8.0, 2.8.1, 2.8.2, 2.8.3, 2.8.4, 2.9.0].
    - broadway/broadway 0.7.0 requires ramsey/uuid ~2.4 -> satisfiable by ramsey/uuid[2.4.0, 2.5.0, 2.6.0, 2.6.1, 2.7.0, 2.7.1, 2.7.2, 2.7.3, 2.7.4, 2.8.0, 2.8.1, 2.8.2, 2.8.3, 2.8.4, 2.9.0].
    - broadway/broadway 0.7.1 requires ramsey/uuid ~2.4 -> satisfiable by ramsey/uuid[2.4.0, 2.5.0, 2.6.0, 2.6.1, 2.7.0, 2.7.1, 2.7.2, 2.7.3, 2.7.4, 2.8.0, 2.8.1, 2.8.2, 2.8.3, 2.8.4, 2.9.0].
    - broadway/broadway 0.8.0 requires ramsey/uuid ~2.4 -> satisfiable by ramsey/uuid[2.4.0, 2.5.0, 2.6.0, 2.6.1, 2.7.0, 2.7.1, 2.7.2, 2.7.3, 2.7.4, 2.8.0, 2.8.1, 2.8.2, 2.8.3, 2.8.4, 2.9.0].
    - broadway/broadway 0.9.0 requires ramsey/uuid ~2.4 -> satisfiable by ramsey/uuid[2.4.0, 2.5.0, 2.6.0, 2.6.1, 2.7.0, 2.7.1, 2.7.2, 2.7.3, 2.7.4, 2.8.0, 2.8.1, 2.8.2, 2.8.3, 2.8.4, 2.9.0].
    - broadway/broadway 0.4.0 requires rhumsaa/uuid ~2.4 -> satisfiable by ramsey/uuid[2.8.1, 2.8.2, 2.8.3, 2.8.4, 2.9.0], rhumsaa/uuid[2.4.0, 2.5.0, 2.6.0, 2.6.1, 2.7.0, 2.7.1, 2.7.2, 2.7.3, 2.7.4, 2.8.0, 2.8.1, 2.8.2].
    - broadway/broadway 0.5.0 requires rhumsaa/uuid ~2.4 -> satisfiable by ramsey/uuid[2.8.1, 2.8.2, 2.8.3, 2.8.4, 2.9.0], rhumsaa/uuid[2.4.0, 2.5.0, 2.6.0, 2.6.1, 2.7.0, 2.7.1, 2.7.2, 2.7.3, 2.7.4, 2.8.0, 2.8.1, 2.8.2].
    - broadway/broadway 0.5.1 requires rhumsaa/uuid ~2.4 -> satisfiable by ramsey/uuid[2.8.1, 2.8.2, 2.8.3, 2.8.4, 2.9.0], rhumsaa/uuid[2.4.0, 2.5.0, 2.6.0, 2.6.1, 2.7.0, 2.7.1, 2.7.2, 2.7.3, 2.7.4, 2.8.0, 2.8.1, 2.8.2].
    - broadway/broadway 0.5.2 requires rhumsaa/uuid ~2.4 -> satisfiable by ramsey/uuid[2.8.1, 2.8.2, 2.8.3, 2.8.4, 2.9.0], rhumsaa/uuid[2.4.0, 2.5.0, 2.6.0, 2.6.1, 2.7.0, 2.7.1, 2.7.2, 2.7.3, 2.7.4, 2.8.0, 2.8.1, 2.8.2].
    - Can only install one of: ramsey/uuid[2.4.0, 3.4.1].
    - Can only install one of: ramsey/uuid[2.5.0, 3.4.1].
    - Can only install one of: ramsey/uuid[2.7.1, 3.4.1].
    - Can only install one of: ramsey/uuid[2.7.2, 3.4.1].
    - Can only install one of: ramsey/uuid[2.7.3, 3.4.1].
    - Can only install one of: ramsey/uuid[2.7.4, 3.4.1].
    - Can only install one of: ramsey/uuid[2.8.0, 3.4.1].
    - Can only install one of: ramsey/uuid[2.8.1, 3.4.1].
    - Can only install one of: ramsey/uuid[2.8.2, 3.4.1].
    - Can only install one of: ramsey/uuid[2.8.3, 3.4.1].
    - Can only install one of: ramsey/uuid[2.8.4, 3.4.1].
    - Can only install one of: ramsey/uuid[2.9.0, 3.4.1].
    - don't install rhumsaa/uuid 2.4.0|don't install ramsey/uuid 3.4.1
    - don't install rhumsaa/uuid 2.5.0|don't install ramsey/uuid 3.4.1
    - don't install rhumsaa/uuid 2.7.1|don't install ramsey/uuid 3.4.1
    - don't install rhumsaa/uuid 2.7.2|don't install ramsey/uuid 3.4.1
    - don't install rhumsaa/uuid 2.7.3|don't install ramsey/uuid 3.4.1
    - don't install rhumsaa/uuid 2.7.4|don't install ramsey/uuid 3.4.1
    - don't install rhumsaa/uuid 2.8.0|don't install ramsey/uuid 3.4.1
    - don't install rhumsaa/uuid 2.8.1|don't install ramsey/uuid 3.4.1
    - don't install rhumsaa/uuid 2.8.2|don't install ramsey/uuid 3.4.1
    - Installation request for ramsey/uuid (locked at 3.4.1) -> satisfiable by ramsey/uuid[3.4.1].

Installation failed, reverting ./composer.json to its original content.

~3.0 or ~0.3?

To get this to install, I had to do composer require nwidart/laravel-broadway=~0.3, not composer require nwidart/laravel-broadway=~3.0 as the readme states. Sorry if I'm being pedantic, I was just getting a little frustrated trying to pull this down.

Dependency Conflicts

composer require nwidart/laravel-broadway=~1.0
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - nwidart/laravel-broadway 1.0.0 requires broadway/broadway 0.10 -> satisfiable by broadway/broadway[0.10.0].
    - Installation request for nwidart/laravel-broadway ~1.0 -> satisfiable by nwidart/laravel-broadway[1.0.0].
    - Conclusion: remove ramsey/uuid 3.6.1
    - Conclusion: don't install ramsey/uuid 3.6.1
    - broadway/broadway 0.10.0 requires ramsey/uuid ~2.4 -> satisfiable by ramsey/uuid[2.4.0, 2.5.0, 2.6.0, 2.6.1, 2.7.0, 2.7.1, 2.7.2, 2.7.3, 2.7.4, 2.8.0, 2.8.1, 2.8.2, 2.8.3, 2.8.4, 2.9.0].
    - Can only install one of: ramsey/uuid[2.4.0, 3.6.1].
    - Can only install one of: ramsey/uuid[2.5.0, 3.6.1].
    - Can only install one of: ramsey/uuid[2.6.0, 3.6.1].
    - Can only install one of: ramsey/uuid[2.6.1, 3.6.1].
    - Can only install one of: ramsey/uuid[2.7.0, 3.6.1].
    - Can only install one of: ramsey/uuid[2.7.1, 3.6.1].
    - Can only install one of: ramsey/uuid[2.7.2, 3.6.1].
    - Can only install one of: ramsey/uuid[2.7.3, 3.6.1].
    - Can only install one of: ramsey/uuid[2.7.4, 3.6.1].
    - Can only install one of: ramsey/uuid[2.8.0, 3.6.1].
    - Can only install one of: ramsey/uuid[2.8.1, 3.6.1].
    - Can only install one of: ramsey/uuid[2.8.2, 3.6.1].
    - Can only install one of: ramsey/uuid[2.8.3, 3.6.1].
    - Can only install one of: ramsey/uuid[2.8.4, 3.6.1].
    - Can only install one of: ramsey/uuid[2.9.0, 3.6.1].
    - Installation request for ramsey/uuid (locked at 3.6.1) -> satisfiable by ramsey/uuid[3.6.1].


Conflict with laravel 5.7.9

I have conflict when I try to install this package. I have a laravel 5.7.9 application and when I try to launch composer command returns me this error:

Problem 1
    - Conclusion: remove laravel/framework v5.7.9
    - Conclusion: don't install laravel/framework v5.7.9
    - nwidart/laravel-broadway 2.0.0 requires illuminate/support 5.1.*|5.2.*|5.3.*|5.4.* -> satisfiable by illuminate/support[5.1.x-dev, 5.2.x-dev, 5.3.x-dev, 5.4.x-dev, v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.30, v5.1.31, v5.1.41, v5.1.6, v5.1.8, v5.2.0, v5.2.19, v5.2.21, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.31, v5.2.32, v5.2.37, v5.2.43, v5.2.45, v5.2.6, v5.2.7, v5.3.0, v5.3.16, v5.3.23, v5.3.4, v5.4.0, v5.4.13, v5.4.17, v5.4.19, v5.4.27, v5.4.36, v5.4.9].
    - nwidart/laravel-broadway 2.0.1 requires illuminate/support 5.1.*|5.2.*|5.3.*|5.4.*|5.5.* -> satisfiable by illuminate/support[5.1.x-dev, 5.2.x-dev, 5.3.x-dev, 5.4.x-dev, 5.5.x-dev, v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.30, v5.1.31, v5.1.41, v5.1.6, v5.1.8, v5.2.0, v5.2.19, v5.2.21, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.31, v5.2.32, v5.2.37, v5.2.43, v5.2.45, v5.2.6, v5.2.7, v5.3.0, v5.3.16, v5.3.23, v5.3.4, v5.4.0, v5.4.13, v5.4.17, v5.4.19, v5.4.27, v5.4.36, v5.4.9, v5.5.0, v5.5.16, v5.5.17, v5.5.2, v5.5.28, v5.5.33, v5.5.34, v5.5.35, v5.5.36, v5.5.37, v5.5.39, v5.5.40, v5.5.41, v5.5.43, v5.5.44].
    - illuminate/support 5.2.x-dev conflicts with laravel/framework[v5.7.9].
    - illuminate/support 5.3.x-dev conflicts with laravel/framework[v5.7.9].
    - illuminate/support 5.4.x-dev conflicts with laravel/framework[v5.7.9].
    - illuminate/support 5.5.x-dev conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.2.43 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.2.45 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.3.0 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.3.16 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.3.23 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.3.4 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.4.0 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.4.13 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.4.17 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.4.19 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.4.27 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.4.36 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.4.9 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.5.0 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.5.16 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.5.17 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.5.2 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.5.28 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.5.35 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.5.36 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.5.37 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.5.39 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.5.40 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.5.41 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.5.43 conflicts with laravel/framework[v5.7.9].
    - illuminate/support v5.5.44 conflicts with laravel/framework[v5.7.9].
    - don't install illuminate/support 5.1.x-dev|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.1.1|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.1.13|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.1.16|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.1.2|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.1.20|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.1.22|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.1.25|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.1.28|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.1.30|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.1.31|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.1.41|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.1.6|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.1.8|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.2.0|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.2.19|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.2.21|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.2.24|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.2.25|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.2.26|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.2.27|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.2.28|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.2.31|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.2.32|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.2.37|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.2.6|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.2.7|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.5.33|don't install laravel/framework v5.7.9
    - don't install illuminate/support v5.5.34|don't install laravel/framework v5.7.9
    - Installation request for laravel/framework v5.7.9 -> satisfiable by laravel/framework[v5.7.9].
    - Installation request for nwidart/laravel-broadway ^2.0 -> satisfiable by nwidart/laravel-broadway[2.0.0, 2.0.1].

```

Upgrade broadway version

Is possible to use broadway 2.x instead of broadway ~1.0.0?
It could be a new version to be update with broadway library, what do you think?

Handler not called

Hi, I take my own broadway project and I want to apply it to my laravel app.

I have tried to configure all starting form the handler, but seems that when I dispatch the command the handler is not called.

This is my BroadwayServiceProvider, I miss something?

class BroadwayServiceProvider extends ServiceProvider {

   
    public function register()
    {
        $this->bindEventSourcedRepositories();
        $this->registerCommandSubscribers();
    }
    public function boot()
    {
    }
   
    private function bindEventSourcedRepositories()
    {
        $this->app->bind(EventSourcingRepository::class, function ($app) {
            $eventStore = $app[\Broadway\EventStore\EventStore::class];
            $eventBus = $app[\Broadway\EventHandling\EventBus::class];
            return new ProcedureRepository($eventStore, $eventBus);
        });
    }

   
    private function registerCommandSubscribers()
    {
        $procedureCommandHandler = new ProcedureCommandHandler($this->app[ProcedureRepository::class]);
        $this->app['laravelbroadway.command.registry']->subscribe([
            $procedureCommandHandler
        ]);
    }
}

This is my command:

class ProcedureChangeState
{
    /**
     * @var UuidInterface
     */
    private $id;

    public function __construct(UuidInterface $id)
    {
        $this->id = $id;
    }

    /**
     * @return UuidInterface
     */
    public function getId(): UuidInterface
    {
        return $this->id;
    }
}

This is my handler

class ProcedureCommandHandler extends SimpleCommandHandler
{
    /**
     * @var Repository
     */
    private $repository;

    public function __construct(Repository $repository)
    {
        $this->repository = $repository;
    }

    public function handleChangeState(ProcedureChangeState $command)
    {
        $procedure = Procedure::changeState($command->getId());

        $this->repository->save($procedure);
    }
}

And this is my aggregate:

class Procedure extends EventSourcedAggregateRoot
{

    private $id;

    public static function changeState(UuidInterface $id)
    {
        $lot = new self();

        $lot->apply(new ProcedureWasChangedState($id));

        return $lot;
    }

    protected function applyChangeState(ProcedureWasChangedState $procedureWasChangedState)
    {
        $this->id = $procedureWasChangedState->getId();
    }

    /**
     * @return string
     */
    public function getAggregateRootId(): string
    {
        return $this->id->toString();
    }
}

How to fire the handler?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.