/event-store-mongodb

Event store implementation using MongoDB

Primary LanguagePHPMIT LicenseMIT

broadway/event-store-mongodb

build status

Installation:

Install package via composer

$ composer require broadway/event-store-mongodb

Configuration

Register the services

parameters:
    mongodb_host: localhost
    mongodb_port: 27107
    mongodb_database: default 
    
services:
    broadway.event_store.mongodb_client:
        class: MongoDB\Client
        arguments: ['mongodb://%mongodb_host%:%mongodb_port%']
    
    broadway.event_store.mongodb_collection:
        class: MongoDB\Collection
        factory: ['@broadway.event_store.mongodb_client', selectCollection]
        arguments: ['%mongodb_database%', 'events']
    
    broadway.event_store.mongodb:
        class: Broadway\EventStore\MongoDB\MongoDBEventStore
        arguments: ['@broadway.event_store.mongodb_collection', '@broadway.serializer.payload', '@broadway.serializer.metadata']

Create index for events collection

db.getCollection('events').createIndex({'uuid': 1, 'playhead': 1},{'unique': 1});

Testing

For testing you need a running MongoDB instance. To start a local MongoDB you can use the provided docker-compose.yml:

docker-compose up -d

To run the tests:

./vendor/bin/phpunit