Skip to content

Instantly share code, notes, and snippets.

@dasjestyr
Created February 26, 2017 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dasjestyr/73b30a9c60491381566ca096a6a28a35 to your computer and use it in GitHub Desktop.
Save dasjestyr/73b30a9c60491381566ca096a6a28a35 to your computer and use it in GitHub Desktop.
EventStore metadata issue
public void CatchUpSubscription(
string streamName,
int lastSeenIndex,
Action<EventInfo, int> processAction)
{
_processAction = processAction;
int? startIndex = lastSeenIndex;
if (lastSeenIndex == -2)
startIndex = null;
Logger.Debug($"Subscribing to {streamName} as catch-up subscription at index {lastSeenIndex}...", this);
var settings = new CatchUpSubscriptionSettings(10000, 100, false, true);
var sub = _eventStore.SubscribeToStreamFrom(
streamName,
startIndex,
settings,
EventAppeared);
_disposableCollection.Add(() => sub.Stop());
}
private void EventAppeared(EventStoreCatchUpSubscription eventStoreCatchUpSubscription, ResolvedEvent resolvedEvent)
{
EventAppeared(resolvedEvent);
}
private void EventAppeared(ResolvedEvent resolvedEvent)
{
if (_processAction == null)
throw new InvalidOperationException("The process action was not set.");
try
{
Logger.Debug($"EVENT READ: {resolvedEvent.Event.EventType} ({resolvedEvent.Event.EventStreamId})", this);
// fails below because I'm not expecting $metadata
EventInfo info;
if (!_deserializationFactory.TryDeserialize(resolvedEvent.Event.Data, resolvedEvent.Event.Metadata, out info))
{
Process(info, resolvedEvent.OriginalEventNumber);
return;
}
Logger.Error($"Could not deserialize event {resolvedEvent.Event.EventType}.", this);
}
catch (Exception ex)
{
Logger.Fatal($"Could not deserialize event. {ex.Message}", this, ex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment