DeSmart / laravel-event-sourcing by DeSmart

Laravel bindings for DeSmart Event Sourcing package
37
7
7
Package Data
Maintainer Username: DeSmart
Maintainer Contact: radmen@desmart.com (Radoslaw Mejer)
Package Create Date: 2016-05-23
Package Last Update: 2016-05-25
Language: PHP
License: MIT
Last Refreshed: 2024-12-19 03:14:03
Package Statistics
Total Downloads: 37
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 7
Total Watchers: 7
Total Forks: 0
Total Open Issues: 0

Laravel Event Sourcing

Simple Laravel implementation of event sourcing mechanism.

Latest version Build Status Software License

Be advised: this package is work in progress and some breaking changes may appear on the way.

Package realizes concept of event sourcing with Laravel framework. Package consists of two main elements: implementation of database-like event store and projection manager.

Event store is a append-only storage dedicated for storing events. Projection manager allows to register projections and update them with generated stream of events.

Installation

To install the package via Composer, simply run the following command:

composer require desmart/laravel-event-sourcing

In order to use provided event store implementation, register service provider in your config/app.php file:

'providers' => [
    // ...
    
    DeSmart\EventSourcing\Laravel\EventStore\ServiceProvider::class,
]

In order to use projection manager, register service provider in your config/app.php file:

'providers' => [
    // ...
    
    DeSmart\EventSourcing\Laravel\Projections\ServiceProvider::class,
]

After registering service provider(s), run artisan command to publish configuration files:

php artisan vendor:publish

Configuration

Package adds two configuration files: event-store.php and read-model.php.

event-store.php

Here you can configure:

  • which connection will be used to connect with your event store,
  • which event's payload serializer will be used.
return [
    /*
    |-------------------------------------------------------------------------------------
    | Database Connection For Event Store
    |-------------------------------------------------------------------------------------
    |
    | Specify which database connection should be used for storing events in events store.
    | All database connections can be found in config/database.php configuration file.
    |
    */

    'connection' => null,

    /*
    |-------------------------------------------------------------------------------------
    | Event Store Payload Serializer
    |-------------------------------------------------------------------------------------
    |
    | Serializer used for serializing/deserializing event and it's payload.
    |
    | Payload is usually of array type. It is sufficient to store payload in 
    | JSON format.
    |
    | Supported serializers: 
    | - 'JsonSerializer' -> use for event store that does not have automatic json serialization/deserialization, like mysql databases
    | - 'ArraySerializer -> use for event store that has automatic json serialization/deserialization, like mongodb databases
    |
    */
    
    'serializer' => \DeSmart\EventSourcing\Laravel\EventStore\Serializers\JsonSerializer::class
];

read-model.php

Here you can register all projections that should be notified with stream of events.

return [
    /*
    |--------------------------------------------------------------------------
    | Read Model Projections
    |--------------------------------------------------------------------------
    |
    | Array of projection classes.
    |
    | These projections will be notified about saved stream of events and they
    | can react with read model updates.
    |
    */
    
    'projections' => []
];

Event store implementation

This package's event store implementation was successfully used/tested with MySql database, MongoDB database as well as with mix of the two: one database served as an event store, where second was storing projections.

Event store required structure (however different column types allowed) can be found here.

License

Package is released under the MIT License (MIT). Please, check LICENSE for more details.

Example usage

For example use of event store as well as project manager, check example/ directory.

Additionally, package provides artisan command for rebuilding all projections:

php artisan projections:rebuild