Download the PHP package mannum/laravel-eventstore without Composer
On this page you can find all versions of the php package mannum/laravel-eventstore. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mannum/laravel-eventstore
More information about mannum/laravel-eventstore
Files in mannum/laravel-eventstore
Package laravel-eventstore
Short Description All things regarding integrating Greg Young's Event Store into Laravel
License MIT
Homepage https://github.com/digitalrisks/laravel-event-store
Informations about the package laravel-eventstore
Laravel EventStore
This package integrates Greg Young's eventstore
into Laravel's event system. By simply implementing ShouldBeStored
on your events, they will be sent to eventstore. In the same fashion you can also setup listeners that can respond to events that are received from the eventstore.
Example implementation: https://github.com/digitalrisks/laravel-eventstore-example
Installation
You can install the package via composer:
Add the base service provider for the package.
In your config/app.php
file, add the following to the providers
array.
Example Event
Usage - Sending Events
The package will automatically send events dispatched in Laravel that implement the ShouldBeStored
interface.
To assist in implementing the interface, the package comes with a SendsToEventStore
trait which meets the requirements of the interface in a basic fashion:
- Event Type: the event's class name
- Event ID: A UUID v4 will be generated
- Data: all of the events public properties are automatically serialized
- Metadata: data from all of the methods marked with
@metadata
will be collected and serialized
Then raising an event is done in the normal Laravel way:
Metadata
Metadata can help trace events around your system. You can include any of the following traits on your event to attach metadata automatically
AddsHerokuMetadata
AddsLaravelMetadata
AddsUserMetaData
Or you can define your own methods to collect metadata. Any method with the @metadata
annotation will be called:
Testing
If you would like to test that your events are being fired correctly, you can use the Laravel Event::mock
method, or the package comes with helpers that interact with an eventstore to confirm they have been stored correctly.
Usage - Receiving Events
You must first run the worker which will listen for events.
None of the options are required. By default it will run the persistance subscription with a timeout of 10 seconds and 1 parallel event at a time.
When an event is received, it will be mapped to the Laravel event and the original EventRecord
can be accessed via getEventRecord()
.
You can react to these events in the normal Laravel fashion.
If you are listening to the same stream where you are firing events, your events WILL BE fired twice - once by Laravel and once received from the event store. You may choose react synchronously if $event->getEventRecord()
is false and asynchronously if $event->getEventRecord()
returns the eventstore record.
In addition, if you would like to test that are events are created AND how the application reacts to those events
you may set eventstore.connection
to sync
. This will trick the event listeners into thinking that the
event has been received from the eventstore.
Testing
If you would like to test your listeners, the package comes with several helper methods to mimic events being received from the worker.
In addition you may set set eventstore.connection
to sync
, which will trick your listeners
Usage - Replaying Events
You can replay events by using the replay command
`
<event>
can be a single event number or a range like 390-396
Configuration
The defaults are set in config/eventstore.php
. Copy this file to your own config directory to modify the values:
php artisan vendor:publish --provider="DigitalRisks\LaravelEventStore\ServiceProvider"
Testing
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Pawel Trauth
- Craig Morris
- Kani Robinson
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-eventstore with dependencies
guzzlehttp/guzzle Version ^6.3 || ^7.0
illuminate/support Version 5.7.* || 5.8.* || ^6.0 || ^7.0 || ^8.0
ramsey/uuid Version ^3.8 || ^4.0
rxnet/eventstore-client Version dev-ramsey-uuid-4