Download the PHP package digitalrisks/lese without Composer
On this page you can find all versions of the php package digitalrisks/lese. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download digitalrisks/lese
More information about digitalrisks/lese
Files in digitalrisks/lese
Package lese
Short Description Laravel Event Sourcing Eventstore bridge layer
License MIT
Informations about the package lese
Laravel Event Sourcing and Eventstore (lese) Bridge
Or German for read
which is somewhat applicable to Event Sourcing. It's almost a good name.
This package swaps out the Event and Snapshot storage model for Laravel Event Souring with EventStore. EventStore has a few advantages over a database in that it is purpose built for event sourcing.
The package also includes a subscribe command so that you may listen to events origination from other services in your system.
Installation
First of all let's bring in the package and Laravel Event Sourcing into our Laravel app.
Then publish the Laravel Event Sourcing and Lese configuration files.
Then jump into config/event-sourcing.php
to configure EventStore as our event and snapshot storage repositories.
Configuration
This is the default content of the config file that will be published at config/lese.php
Getting Started
I would recommend getting familiar with Event Sourcing by reading through the excellent guide at https://docs.spatie.be/laravel-event-sourcing/v3/introduction/.
The next step is to get a local version of the EventStore running (you won't need a database). There are instructions for every platform at https://eventstore.com/docs/getting-started/index.html
Let's now create a simple event:
And fire it off:
Let's create a simple Projection to put account information in a database.
And also send an event to the FBI for large transactions:
If, later on, the business wants to have an attribute on the model for number_of_deposits
, we update the Projector:
And re-run the events:
Learn more how to use Event Sourcing by following the guides at https://docs.spatie.be/laravel-event-sourcing/v3/introduction/
Aggregates
If you're not using aggregates, you can skip this section.
In order for the EventStore repositories to fetch the events and/or snapshots related to an aggregate, it needs to know about the aggregate. To do this we simply override the two methods below to initiate the repostiory and pass in the aggregate.
Subscribing to Streams
The package also includes a long-running process, similar to Pub / Sub with php artisan redis:subscribe
whereby you can listen to events from a stream.
Let's say this is the the accounts-service
but we wanted listen for events from the quotes-service
. When a quote is converted, we want to create an account for it.
Careful: If you listen to events that you publish, projectors and reactors will process them once in your application and again when they come back down the stream. It's recommended you subscribe only to streams that you don't publish to.
In config/lese.php
we would add the stream for quote converted events:
We could then run the following command to create the persistent subscriptions on EventStore
Careful: When resetting persistent subscriptions, it will start from the first event again. If you have reactors, you should go into the eventstore admin and set the
start from
value to the event number you want to start from.
And finally start the subscribe process
Event 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:
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
- Freek Van der Herten
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of lese with dependencies
prooph/event-store-http-client Version ^1.0@beta
php-http/guzzle6-adapter Version ^2.0
prooph/event-store-client Version ^1.0@RC