예제 #1
0
        public void FlagSubscriptionAsPoisoned(IEvent poisonedEvent, PoisonMessageException exception)
        {
            using (var context = this.contextFactory.Invoke(false))
            {
                var subscription = context.Subscriptions.Where(s => s.StreamType == poisonedEvent.StreamType && s.SubscriberStreamType == this.streamType).Single();
                subscription.IsPoisoned      = true;
                subscription.UpdateLocalTime = this.time.Now.ToLocalTime();
                subscription.PoisonEventCollectionVersion = poisonedEvent.EventCollectionVersion;
                try
                {
                    subscription.ExceptionMessage = this.serializer.Serialize(exception);
                }
                catch (Exception)
                {
                    subscription.ExceptionMessage = string.Format("Exception type: {0}. Exception message: {1}. Inner exception: {2}", exception.GetType().Name, exception.Message, exception.InnerException.Message != null ? exception.InnerException.Message : "null");
                }
                try
                {
                    subscription.DeadLetterPayload = this.serializer.Serialize(poisonedEvent);
                }
                catch (Exception)
                {
                    subscription.DeadLetterPayload = string.Format("EventType: {0}", poisonedEvent.GetType().Name);
                }

                context.SaveChanges();
            }
        }
        public void FlagSubscriptionAsPoisoned(IEvent poisonedEvent, PoisonMessageException exception)
        {
            string exceptionMessage;

            try
            {
                exceptionMessage = this.serializer.Serialize(exception);
            }
            catch (Exception)
            {
                exceptionMessage = string.Format("Exception type: {0}. Exception message: {1}. Inner exception: {2}", exception.GetType().Name, exception.Message, exception.InnerException.Message != null ? exception.InnerException.Message : "null");
            }

            string deadLetterPayload;

            try
            {
                deadLetterPayload = this.serializer.Serialize(poisonedEvent);
            }
            catch (Exception)
            {
                deadLetterPayload = string.Format("EventType: {0}", poisonedEvent.GetType().Name);
            }

            this.sql.ExecuteNonQuery(this.markAsPoisoned,
                                     new SqlParameter("@UpdateLocalTime", this.time.Now.ToLocalTime()),
                                     new SqlParameter("@PoisonEventCollectionVersion", poisonedEvent.EventCollectionVersion),
                                     new SqlParameter("@ExceptionMessage", SqlDbType.NVarChar)
            {
                Value = exceptionMessage
            },
                                     new SqlParameter("@DeadLetterPayload", SqlDbType.NVarChar)
            {
                Value = deadLetterPayload
            },
                                     new SqlParameter("@SubscriberStreamType", this.streamType),
                                     new SqlParameter("@StreamType", poisonedEvent.StreamType));
        }