How to use SingleStreamStrategy? #40
Copy link
Copy link
Open
Labels
Description
I'm trying to enable SingleStreamStrategy to fix performance issues in projections (see proophsoftware/es-emergency-call#5 for details).
For now I'm unable to get it working. EventStore still makes one stream per aggregate instead of per aggregate type. Here is my current configuration:
services:
Prooph\EventStore\Pdo\PostgresEventStore:
arguments: ['@messageFactory', '@eventStoreConnection', '@stream_strategy']
stream_strategy:
class: Prooph\EventStore\Pdo\PersistenceStrategy\PostgresSingleStreamStrategyIn the documentation I found a link to this example to initialize the streams. This creates one more stream in the database but the EventStore is still creating new streams for every new aggregate. Also the example is confusing. Shouldn't I create one stream for each aggregate type instead of just one stream?
Reactions are currently unavailable
Activity
[-]How to use SingleStreamStrategy[/-][+]How to use SingleStreamStrategy?[/+]enumag commentedon Mar 12, 2018
Ok it seems it needs to be configured on each repository definition as well:
Now however eventstore only uses that one stream I created based on the example script linked above. All events from all aggregate types are mixed in this stream. How can I separate them to one stream per aggregate type?
enumag commentedon Mar 12, 2018
Ok more progress. Looks like I need to override
AggregateRepository::determineEventStreamwith this:Now I need to correctly initialize the event streams which means I need to somehow ask prooph for names of all aggregate types that exist throughout the application. How can I do that?
UFOMelkor commentedon Mar 12, 2018
@enumag You don't need to overwrite
AggregateRepository::determineEventStream.It should be enough to set the stream_name in the event-store configuration.
Initializing of the stream is – in my setup – currently part of the database migration. Automation of this sounds tricky. But of course you could get the config of the event store bundle, grab all repositories, filter to get just the one with one stream per aggregate type and create them. I'm just not sure whether this is worth the trouble …
enumag commentedon Mar 12, 2018
@UFOMelkor I didn't realize I need to put that to database migrations. Thanks for pointing it out.
Well this pretty much resolves this issue for me. But it is probably a good idea to add some notes to the documentation about how to setup the SingleStreamStrategy. As you can see I've spent some time to get it working so it's not exactly clear.
UFOMelkor commentedon Mar 12, 2018
Definitely – I will let the issue open for the documentation 👍
webdevilopers commentedon Apr 14, 2020
There is a command by @gquemener that comes with the symfony recipe:
You can adapt it to your needs e.g.:
And then call it via
acme:create-event-streamsinstead of the original callevent-store:event-stream:create.