Example #1
0
        private MessageReleaseAction OnMessageReceived(BrokeredMessage message)
        {
            // NOTE: type information does not belong here. It's a responsibility
            // of the serializer to be self-contained and put any information it
            // might need for rehydration.

            object payload;

            using (var stream = message.GetBody <Stream>())
                using (var reader = new StreamReader(stream))
                {
                    try
                    {
                        payload = this.serializer.Deserialize(reader);
                    }
                    catch (SerializationException e)
                    {
                        return(MessageReleaseAction.DeadLetterMessage(e.Message, e.ToString()));
                    }
                }

            // TODO: have a better trace correlation mechanism (that is used in both the sender and receiver).
            string traceIdentifier = BuildTraceIdentifier(message);

            try
            {
                ProcessMessage(traceIdentifier, payload, message.MessageId, message.CorrelationId);
            }
            catch (Exception e)
            {
                return(HandleProcessingException(message, traceIdentifier, e));
            }

            return(CompleteMessage(message, traceIdentifier));
        }
Example #2
0
 private MessageReleaseAction HandleProcessingException(BrokeredMessage message, string traceIdentifier, Exception e)
 {
     if (message.DeliveryCount > MaxProcessingRetries)
     {
         Trace.TraceError("An error occurred while processing the message" + traceIdentifier + " and will be dead-lettered:\r\n{0}", e);
         return(MessageReleaseAction.DeadLetterMessage(e.Message, e.ToString()));
     }
     else
     {
         Trace.TraceWarning("An error occurred while processing the message" + traceIdentifier + " and will be abandoned:\r\n{0}", e);
         return(MessageReleaseAction.AbandonMessage);
     }
 }