Created
February 26, 2017 01:31
-
-
Save dasjestyr/73b30a9c60491381566ca096a6a28a35 to your computer and use it in GitHub Desktop.
EventStore metadata issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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