Ejemplo n.º 1
0
        private MessageReleaseAction OnMessageReceived(Message 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 = new MemoryStream(message.Body))
                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));
        }
Ejemplo n.º 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()));
     }
     Trace.TraceWarning("An error occurred while processing the message" + traceIdentifier + " and will be abandoned:\r\n{0}", e);
     return(MessageReleaseAction.AbandonMessage);
 }
Ejemplo n.º 3
0
 private MessageReleaseAction HandleProcessingException(Message message, string traceIdentifier, Exception e)
 {
     if (message.SystemProperties.DeliveryCount > MaxProcessingRetries)
     {
         logger.LogError($"An error occurred while processing the message {traceIdentifier} and will be dead-lettered:\r\n{e.Message}");
         return(MessageReleaseAction.DeadLetterMessage(e.Message, e.ToString()));
     }
     else
     {
         logger.LogWarning($"An error occurred while processing the message {traceIdentifier} and will be abandoned:\r\n{e.Message}");
         return(MessageReleaseAction.AbandonMessage);
     }
 }