I was using fromStreams as my function is basically just toLink and is identical for each event type.
My requirement is to append to certain streams all events of certain types. Using et- streams seemed natural. I have very small numer of events and performance is not an issue.
If you recommend using fromAll I can switch without any problem.
Any guidance is very helpful as the documentation is a bit sparse yet. (No hard feelings intended, I do understand your priorities!)
Thank you your your suggestions. I’ve rewritten my projection as
fromAll()
.when({
$init: function () {
return { }; // initial state
},
Core_AccountManagement_BranchCreated: function (state, ev) {
if (ev.metadata && ev.metadata.Tenant) {
linkTo(ev.metadata.Tenant + '-Core_Sales_Branch-' + ev.data.Id, ev);
}
return state;
},
Core_AccountManagement_BranchCodeChanged: function (state, ev) {
if (ev.metadata && ev.metadata.Tenant) {
linkTo(ev.metadata.Tenant + '-Core_Sales_Branch-' + ev.data.Id, ev);
}
return state;
},
Core_AccountManagement_BranchRenamed: function (state, ev) {
if (ev.metadata && ev.metadata.Tenant) {
linkTo(ev.metadata.Tenant + '-Core_Sales_Branch-' + ev.data.Id, ev);
}
return state;
},
Core_AccountManagement_BranchDeleted: function (state, ev) {
if (ev.metadata && ev.metadata.Tenant) {
linkTo(ev.metadata.Tenant + '-Core_Sales_Branch-' + ev.data.Id, ev);
}
return state;
}
});
The projection can be saved and started without any issues.
However, when I start writing the events the projection errors and its status changes to Faulted. If I start it again the status changes to Running but I see more errors in the log.
The problem is projections assume exclusive access to the output stream. Otherwise it becomes impossible to make projections recoverable in case of a crash. You can typically write your events to independent stream and then join streams with this or another projection.