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));
        }
        private void ReleaseMessage(BrokeredMessage msg, MessageReleaseAction releaseAction, long processingElapsedMilliseconds, long schedulingElapsedMilliseconds, Stopwatch roundtripStopwatch)
        {
            switch (releaseAction.Kind)
            {
            case MessageReleaseActionKind.Complete:
                msg.SafeCompleteAsync(
                    subscription,
                    success => {
                    msg.Dispose();
                    instrumentation.MessageCompleted(success);
                    if (success)
                    {
                        dynamicThrottling.NotifyWorkCompleted();
                    }
                    else
                    {
                        dynamicThrottling.NotifyWorkCompletedWithError();
                    }
                },
                    processingElapsedMilliseconds,
                    schedulingElapsedMilliseconds,
                    roundtripStopwatch);
                break;

            case MessageReleaseActionKind.Abandon:
                msg.SafeAbandonAsync(
                    subscription,
                    success => {
                    msg.Dispose();
                    instrumentation.MessageCompleted(false);
                    dynamicThrottling.NotifyWorkCompletedWithError();
                },
                    processingElapsedMilliseconds,
                    schedulingElapsedMilliseconds,
                    roundtripStopwatch);
                break;

            case MessageReleaseActionKind.DeadLetter:
                msg.SafeDeadLetterAsync(
                    subscription,
                    releaseAction.DeadLetterReason,
                    releaseAction.DeadLetterDescription,
                    success => {
                    msg.Dispose();
                    instrumentation.MessageCompleted(false);
                    dynamicThrottling.NotifyWorkCompletedWithError();
                },
                    processingElapsedMilliseconds,
                    schedulingElapsedMilliseconds,
                    roundtripStopwatch);
                break;

            default:
                break;
            }
        }
Example #3
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);
     }
 }
        private void ReleaseMessage(BrokeredMessage msg, MessageReleaseAction releaseAction, long processingElapsedMilliseconds, long schedulingElapsedMilliseconds, Stopwatch roundtripStopwatch)
        {
            switch (releaseAction.Kind)
            {
            case MessageReleaseActionKind.Complete:
                msg.CompleteAsync();
                break;

            case MessageReleaseActionKind.Abandon:
                msg.AbandonAsync();
                break;

            case MessageReleaseActionKind.DeadLetter:
                msg.DeadLetterAsync();
                break;

            default:
                break;
            }
        }
Example #5
0
        private void ReleaseMessage(BrokeredMessage msg, MessageReleaseAction releaseAction, Action completeReceive, Action onReleaseError, CountdownEvent countdown, long processingElapsedMilliseconds, long schedulingElapsedMilliseconds, Stopwatch roundtripStopwatch)
        {
            switch (releaseAction.Kind)
            {
            case MessageReleaseActionKind.Complete:
                msg.SafeCompleteAsync(
                    this.subscription,
                    operationSucceeded =>
                {
                    msg.Dispose();
                    this.OnMessageCompleted(operationSucceeded, countdown);
                    if (operationSucceeded)
                    {
                        completeReceive();
                    }
                    else
                    {
                        onReleaseError();
                    }
                },
                    processingElapsedMilliseconds,
                    schedulingElapsedMilliseconds,
                    roundtripStopwatch);
                break;

            case MessageReleaseActionKind.Abandon:
                this.dynamicThrottling.Penalize();
                msg.SafeAbandonAsync(
                    this.subscription,
                    operationSucceeded =>
                {
                    msg.Dispose();
                    this.OnMessageCompleted(false, countdown);

                    onReleaseError();
                },
                    processingElapsedMilliseconds,
                    schedulingElapsedMilliseconds,
                    roundtripStopwatch);
                break;

            case MessageReleaseActionKind.DeadLetter:
                this.dynamicThrottling.Penalize();
                msg.SafeDeadLetterAsync(
                    this.subscription,
                    releaseAction.DeadLetterReason,
                    releaseAction.DeadLetterDescription,
                    operationSucceeded =>
                {
                    msg.Dispose();
                    this.OnMessageCompleted(false, countdown);

                    if (operationSucceeded)
                    {
                        completeReceive();
                    }
                    else
                    {
                        onReleaseError();
                    }
                },
                    processingElapsedMilliseconds,
                    schedulingElapsedMilliseconds,
                    roundtripStopwatch);
                break;

            default:
                break;
            }
        }
        private void ReleaseMessage(BrokeredMessage msg, MessageReleaseAction releaseAction, Action completeReceive, Action onReleaseError, CountdownEvent countdown, long processingElapsedMilliseconds, long schedulingElapsedMilliseconds, Stopwatch roundtripStopwatch)
        {
            switch (releaseAction.Kind)
            {
                case MessageReleaseActionKind.Complete:
                    msg.SafeCompleteAsync(
                        this.subscription,
                        operationSucceeded =>
                        {
                            msg.Dispose();
                            this.OnMessageCompleted(operationSucceeded, countdown);
                            if (operationSucceeded)
                            {
                                completeReceive();
                            }
                            else
                            {
                                onReleaseError();
                            }
                        },
                        processingElapsedMilliseconds,
                        schedulingElapsedMilliseconds,
                        roundtripStopwatch);
                    break;
                case MessageReleaseActionKind.Abandon:
                    this.dynamicThrottling.Penalize();
                    msg.SafeAbandonAsync(
                        this.subscription,
                        operationSucceeded =>
                        {
                            msg.Dispose();
                            this.OnMessageCompleted(false, countdown);

                            onReleaseError();
                        },
                        processingElapsedMilliseconds,
                        schedulingElapsedMilliseconds,
                        roundtripStopwatch);
                    break;
                case MessageReleaseActionKind.DeadLetter:
                    this.dynamicThrottling.Penalize();
                    msg.SafeDeadLetterAsync(
                        this.subscription,
                        releaseAction.DeadLetterReason,
                        releaseAction.DeadLetterDescription,
                        operationSucceeded =>
                        {
                            msg.Dispose();
                            this.OnMessageCompleted(false, countdown);

                            if (operationSucceeded)
                            {
                                completeReceive();
                            }
                            else
                            {
                                onReleaseError();
                            }
                        },
                        processingElapsedMilliseconds,
                        schedulingElapsedMilliseconds,
                        roundtripStopwatch);
                    break;
                default:
                    break;
            }
        }
 private void ReleaseMessage(BrokeredMessage msg, MessageReleaseAction releaseAction, long processingElapsedMilliseconds, long schedulingElapsedMilliseconds, Stopwatch roundtripStopwatch)
 {
     switch (releaseAction.Kind)
     {
         case MessageReleaseActionKind.Complete:
             msg.SafeCompleteAsync(
                 this.subscription,
                 success =>
                 {
                     msg.Dispose();
                     this.instrumentation.MessageCompleted(success);
                     if (success)
                     {
                         this.dynamicThrottling.NotifyWorkCompleted();
                     }
                     else
                     {
                         this.dynamicThrottling.NotifyWorkCompletedWithError();
                     }
                 },
                 processingElapsedMilliseconds,
                 schedulingElapsedMilliseconds,
                 roundtripStopwatch);
             break;
         case MessageReleaseActionKind.Abandon:
             msg.SafeAbandonAsync(
                 this.subscription,
                 success => { msg.Dispose(); this.instrumentation.MessageCompleted(false); this.dynamicThrottling.NotifyWorkCompletedWithError(); },
                 processingElapsedMilliseconds,
                 schedulingElapsedMilliseconds,
                 roundtripStopwatch);
             break;
         case MessageReleaseActionKind.DeadLetter:
             msg.SafeDeadLetterAsync(
                 this.subscription,
                 releaseAction.DeadLetterReason,
                 releaseAction.DeadLetterDescription,
                 success => { msg.Dispose(); this.instrumentation.MessageCompleted(false); this.dynamicThrottling.NotifyWorkCompletedWithError(); },
                 processingElapsedMilliseconds,
                 schedulingElapsedMilliseconds,
                 roundtripStopwatch);
             break;
         default:
             break;
     }
 }