Extend IFault Interface To Allow Easier Error Tracking & Recovery

30 views
Skip to first unread message

Mick Delaney

unread,
Apr 16, 2015, 8:15:32 AM4/16/15
to masstrans...@googlegroups.com
Hi,

I was wondering if it would be possible to add some extra context to the generic IFault interface 

 public interface IFault<TMessage>
    {
        /// <summary>
        /// The message that failed to be consumed
        /// </summary>
        TMessage FailedMessage { get; set; }
        /// <summary>
        /// The type of fault that occurred
        /// </summary>
        string FaultType { get; }
        /// <summary>
        /// Messages associated with the exception
        /// </summary>
        List<string> Messages { get; set; }
        /// <summary>
        /// When the exception occurred
        /// </summary>
        DateTime OccurredAt { get; set; }
        /// <summary>
        /// A stack trace related to the exception
        /// </summary>
        List<string> StackTrace { get; set; }
    }


The idea then is to create a generic fault handler, so I can built a UI with a retry button. 


 public class FaultHandler : Consumes<IFault>.Context
    {
        readonly IFaultedMessageCollection _collection;
        public FaultHandler(IFaultedMessageCollection collection)
        {
            _collection = collection;
        }
        public void Consume(IConsumeContext<IFault> ctx)
        {
            var message = ctx.Message;
            var messageData = Newtonsoft.Json.JsonConvert.SerializeObject(message..FailedMessage);
            var faultedMessage = new FaultedMessage
            {
                MessageType = message.FailedMessage.GetType().AssemblyQualifiedName,
                OccurredAt = message.OccurredAt,
                Messages = message.Messages,
                StackTrace = message.StackTrace,
                MessageData = messageData,
                SourceAddress = ctx.SourceAddress.ToString() 
            };
            _collection.Save(faultedMessage);
        }
    }


This seems like a trivial addition but am I right in saying that once the service that is providing the retry UI has access to the Message assemblies 
it could use the SourceAddress to send the message back again to the queue ???? 







Reply all
Reply to author
Forward
0 new messages