Downloads
Stars
Version
This package supports the use of the prooph service buses inside of a Laravel application.
composer require camuthig/service-bus-laravel-package
php artisan vendor:publish
The package will automatically be discovered by Laravel when installed, no changes to include the service provider are needed.
The default instance of each bus type can be retrieved in two ways:
<?php
use \Camuthig\ServiceBus\Package\Test\Fixture\TestEvent;
// Using the facade
\Camuthig\ServiceBus\Package\Facade\EventBus::dispatch(new TestEvent());
// Getting the Prooph interface from the container
app()->make(\Prooph\ServiceBus\EventBus::class)->dispatch(new TestEvent());
Each bus type (command, event and query) includes both a singleton interface as well as a facade.
This package also supports having more than one of each bus type. To leverage a
non-default bus, you will want to use the ServiceBusManager
. The manager gives
you access to all of the buses by name.
The service manager can be retrieved in three ways:
<?php
// As a facade
\Camuthig\ServiceBus\Package\Facade\ServiceBus::eventBus('other_bus');
// Getting the interface from the container
$manager = app()->make(\Camuthig\ServiceBus\Package\Contracts\ServiceBusManager::class);
$manager->eventBus('other_bus');
// Getting the `service_bus` from the container
$manager = app()->make('service_bus');
$manager->eventBus('other_bus');
The buses can be configured using the service_bus.php
configuration file. Each
type of bus will have it's own list of of named buses with the following options:
The router for each bus can be configured with:
MessageBusRouterPlugin
to use for this bus. It
is expected that the constructor for the router should accept an array of
route mappings. See the prooph CommandRouter
, EventRouter
, and
QueryRouter
classes for examples. This will default to the appropriate
prooph router based on the type of the bus if not provided.AsyncSwitchMessageRouter
to add to the bus. If this value is not provided, no switch will be included
on the bus.