承接 morebec/orkestra-postgresql-eventstore 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

morebec/orkestra-postgresql-eventstore

Composer 安装命令:

composer require morebec/orkestra-postgresql-eventstore

包简介

PostgreSQL Event Store for Orkestra

README 文档

README

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

统计信息

  • 总下载量: 425
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2021-04-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固