/// <summary> /// Catches up subscription event appeared. /// </summary> /// <param name="subscription">The subscription.</param> /// <param name="resolvedEvent">The resolved event.</param> /// <param name="endpointId">The endpoint identifier.</param> /// <returns></returns> private async Task CatchUpSubscriptionEventAppeared(EventStoreCatchUpSubscription subscription, ResolvedEvent resolvedEvent, Guid catchUpSubscriptionId, Guid endpointId) { try { // Check the event data has been received if (this.EventAppeared != null) { // Serialise the event data String serialisedData = JsonConvert.SerializeObject(resolvedEvent); SubscriptionDataTransferObject subscriptionInformation = new SubscriptionDataTransferObject() { SerialisedData = serialisedData, EventId = (Guid)((RecordedEvent)resolvedEvent.Event).EventId, SubscriptionGroupId = catchUpSubscriptionId.ToString(), }; var handledSuccessfully = await this.EventAppeared(subscriptionInformation); if (!handledSuccessfully) { throw new Exception($"Failed to Process Event {resolvedEvent.Event.EventId} on catchup subscription group {catchUpSubscriptionId}"); } } else { Logger.LogInformation("Unable to process event as EventAppeared Event handler is null"); } } catch (Exception ex) { Logger.LogError(ex); } }
/// <summary> /// Persistents the subscription event appeared. /// </summary> /// <param name="subscription">The subscription.</param> /// <param name="resolvedEvent">The resolved event.</param> /// <param name="subscriptionGroupId">The subscription group identifier.</param> /// <returns></returns> private async Task PersistentSubscriptionEventAppeared(EventStorePersistentSubscriptionBase subscription, ResolvedEvent resolvedEvent, Guid subscriptionGroupId) { try { // Check the event data has been received if (this.EventAppeared != null) { // Serialise the event data //String serialisedData = this.Serialiser.Serialise(resolvedEvent); // Get the event data from the resolved Event var serialisedData = Encoding.UTF8.GetString(resolvedEvent.Event.Data); SubscriptionDataTransferObject subscriptionInformation = new SubscriptionDataTransferObject() { SerialisedData = serialisedData, EventId = (Guid)((RecordedEvent)resolvedEvent.Event).EventId, SubscriptionGroupId = subscriptionGroupId.ToString(), }; var handledSuccessfully = await this.EventAppeared(subscriptionInformation); if (!handledSuccessfully) { throw new Exception( $"Failed to Process Event {resolvedEvent.Event.EventId} on persistent subscription group {subscriptionGroupId}"); } } else { Logger.LogInformation("Unable to process event as EventAppeared Event handler is null"); } // Acknowledge the event subscription.Acknowledge(resolvedEvent); } catch (TimeoutException tex) { subscription.Fail(resolvedEvent, PersistentSubscriptionNakEventAction.Park, tex.Message); } catch (InvalidOperationException ioex) { subscription.Fail(resolvedEvent, PersistentSubscriptionNakEventAction.Skip, ioex.Message); } catch (Exception ex) { subscription.Fail(resolvedEvent, PersistentSubscriptionNakEventAction.Retry, ex.Message); } }