Giter VIP home page Giter VIP logo

orkestra-postgresql-eventstore's Introduction

PostgreSqlEventStore

This component provides an implementation of a the an Event Store (from the EventSourcing Component) using PostgreSQL.

Under the hood, it uses DBAL for communication with PostgreSQL.

Installation

composer require morebec/orkestra-orkestra-postgresql-eventstore

Usage

use Morebec\Orkestra\PostgreSqlEventStore\PostgreSqlEventStore;
use Morebec\Orkestra\PostgreSqlEventStore\PostgreSqlEventStoreConfiguration;

$connection = DriverManager::getConnection([
    'url' => '...'
], new Configuration()); 

$config = new PostgreSqlEventStoreConfiguration();
$store = new PostgreSqlEventStore($connection, $config);

Event Store Subscriptions

The pu/sub mechanism of the event store is implemented using PostgreSQL's LISTEN/NOTIFY feature. Unfortunately given the nature of PHP being a synchronous RunTime, the only way to have Pub/Sub capabilities is to run a LISTEN loop:

// This method will start a loop and listen for communications from PostgreSQL's LISTEN/NOTIFY mechanis.
$store->notifySubscribers();

This is can be used with Event Processors.

PostgreSqlEventStorePositionStorage

An implementation of EventStorePositionStorageInterface is also shipped with the component as the PostgreSqlEventStorePositionStorage, which also relies on DBAL for communication with PostgreSQL:

use Morebec\Orkestra\PostgreSqlEventStore\PostgreSqlEventStorePositionStorage;
use Morebec\Orkestra\PostgreSqlEventStore\PostgreSqlEventStorePositionStorageConfiguration;

$connection = DriverManager::getConnection([
    'url' => '...'
], new Configuration()); 

$config = new PostgreSqlEventStorePositionStorageConfiguration();
$store = new PostgreSqlEventStorePositionStorage($connection, $config);

PostgreSqlEventProcessor

A ready-made implementation of an Event Processor with support for the PostgreSqlEventStore is also provided with this component:

use Morebec\Orkestra\PostgreSqlEventStore\PostgreSqlEventProcessor;
$processor = new PostgreSqlEventProcessor($publisher, $eventStore, $postgreSqlEventStore, $positionStorage);

// This call will loop and notify all event store subscribers as well as the event processor itself
// for event tracking.
$processor->start();

Given that the EventStoreInterface can be decorated, the processor cannot directly use the PostgreSqlEventStore through the EventStoreInterface. Also, since it requires using specific methods from the implementation PostgreSqlEventStore to access some PostgreSQL specific features, the actual instance of the PostgreSqlEventStore must be injected additionally. This is why both are injected in the constructor.

Testing

To run the tests execute the following command:

vendor/bin/phpunit tests/

It is required to have an instance of postgresql running with a password-less role postgres and a database named postgres. To easily get this setup and running a docker-compose configuration file is available at the root of this project.

To run it simply execute the following command:

docker-compose up -d

orkestra-postgresql-eventstore's People

Contributors

jwillp avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.