I have started creating a test application in .Net, that uses EventStore by Greg Young as the backing store for CQRS/ES.
In order to make it easy to load up a full aggregate, I save to a stream with a name of "agg-123". For example for a product aggregate with an id of 553, there would be a stream named "product-553". And then same for an "Order" aggregate, the stream would be named "order-123".
From the rehydrating and saving of events this works well.
I am now attempting to create a listener that will listen to certain streams to then populate a query database. The subscribe methods that I see can only seem to subscribe to "order-123", or "all". I can't see how I would subscribe to "product-" or "order-", or both.
I imagine that either
Anyone any advice?
In your projections you can use fromCategory(). EventStore categorises each stream by the name of the stream up to the first '-'. So your 'order-123' and 'order-456' streams are both in the 'order' category.
So you can do something like:
fromCategory('order')
.whenAny(function(s,e) {
linkTo('orders',e);
});
This will project all order related events from all order aggregates into a single 'orders' stream that you can subscribe.
You'll need to ensure that the category projections are running. (It's been a while since I've used EventStore, it was back when projections were in beta and weren't enabled by default, not sure if things are the same in the latest versions)