I’ve been working around this issue today as well.
As far as i can see you are right that events received over a subscription don’t contain the necessary data to create a position for use with ReadAllEventsForward, so it isn’t very useful for catching up after downtime.
Additionally you cant treat $all like a normal stream, (you get a streamnotfound exception from ReadEventStreamForward)
What i ended up doing was creating a projection that is essentially the same as $all -
fromAll().whenAny(
function(state, event) {
linkTo('temp-all', event);
return state;
}
);
My subscription code then subscribes to just this stream, rather than using SubscribeToAll... For recording progress I just increment a counter as events are dealt with.
The catch up logic just uses ReadEventStreamForward on temp-all, using the counter from the database as the starting point.
The final issue you will notice if you try this approach is that subscriptions to temp-all returns link events, rather than your actual events, which is no use for passing to denormalizers.
At the moment i am resolving this client side by performing another round trip to the event store to get the real event, something like:
if (recordedEvent.EventType.Equals("$>"))
recordedEvent = ResolveLinkEvent(recordedEvent);
private RecordedEvent ResolveLinkEvent(RecordedEvent recordedEvent)
{
var decodedData = Encoding.UTF8.GetString(recordedEvent.Data);
var elements = decodedData.Split(new[] {'@'});
int eventNumber = elements[0];
string streamId = elements[1];
var slice = _eventStoreConnection.ReadEventStreamForward(streamId, eventNumber, 1);
return slice.Events[0];
}
This is a bit crap and inefficient but the actual denormalizers are probably the bottleneck anyway.
Will probably have something on github when this is actually in a state that might be useful for others, but if you are curious my event processor code so far in this gist:
[https://gist.github.com/3990336](https://gist.github.com/3990336)
Cheers,
Rich
PS.
Hope this is readable now!
Google keeps ruining my formatting and running text off the side of the screen!