So I have effectively created a single stream for a category using a projection.
Given the streams:
Foobar-1
Foobar-2
Foobar-3
Foobar-4
I can create a single stream containng all events from those streams by doing the following:
fromCategory(‘Foobar’)
.whenAny(function(s,e) {
linkTo('Foobars',e);
});
This gives me a “Foobars” stream with all events from the four streams listed above
If I want to do this across multiple categories, I am stuck. Let’s say I have the following streams:
Foobar-1
Foobar-2
Barfoo-1
Barfoo-2
How could I create a projection to capture all events across both of those two categories (but no other categories)? I was looking for a “fromCategories” function (like “fromStreams”) but couldn’t find one.
Cheers,
Callum
fromAll and parse the stream name?
This construction works for multiple streams (we use it already):
fromStreams([‘Foobar-1’, ‘Foobar-2’, ‘Barfoo-1’, ‘Barfoo-2’])
.whenAny(function(s,e) {
linkTo('resultStream',e);
});
Or this is not what you want?
I wanted to do it for categories, so "fromStreams" is not so useful. I
don't know all the streams upfront.
While I am sure Greg's solution works, I realised that if I layer some
projections correctly I can do it that way too.
So if I have streams...
Foobar-1
Foobar-2
Barfoo-1
Barfoo-2
Then...
Projection 1 reads the "Foobar" category and writes stream -
"AllTheThings-Foobar".
Projection 2 reads the "Barfoo" category and writes stream -
"AllTheThings-Barfoo".
Projection 3 reads the "AllTheThings" caegory and writes stream
"AllTheThings".
That's pretty useful in my case. The "interim" streams produced by
Projections 1 and 2 give me some more information.
Callum
I realise this post is old, but I needed to do the same thing recently. I solved it by using fromStreams with the system defined category streams, e.g.
fromStreams(["$ce-category1", “$ce-category2”])
.when({
$any: function(s, e) {
linkTo(“MyStream”, e)
}
});
for a small number of streams this works great, as the number rises
fromAll is better