示例#1
0
            public static Dictionary <string, string> RemoveErrorMessageHeaders(Dictionary <string, string> headers)
            {
                var headersToRetryWith = headers
                                         .Where(kv => !KeysToRemoveWhenRetryingAMessage.Contains(kv.Key))
                                         .ToDictionary(kv => kv.Key, kv => kv.Value);

                return(headersToRetryWith);
            }
        public void Handle(PerformRetry message)
        {
            var failedMessage = Session.Load <FailedMessage>(new Guid(message.FailedMessageId));

            if (failedMessage == null)
            {
                throw new ArgumentException("Can't find the failed message with id: " + message.FailedMessageId);
            }

            if (failedMessage.Status != FailedMessageStatus.Unresolved)
            {
                // We only retry messages that are unresolved
                return;
            }

            var attempt = failedMessage.ProcessingAttempts.Last();

            var originalHeaders = attempt.Headers;

            var headersToRetryWith = originalHeaders.Where(kv => !KeysToRemoveWhenRetryingAMessage.Contains(kv.Key))
                                     .ToDictionary(kv => kv.Key, kv => kv.Value);

            headersToRetryWith["ServiceControl.RetryId"] = message.RetryId.ToString();

            using (var stream = BodyStorage.Fetch(attempt.MessageId))
            {
                var transportMessage = new TransportMessage(failedMessage.Id, headersToRetryWith)
                {
                    Body          = ReadFully(stream),
                    CorrelationId = attempt.CorrelationId,
                    Recoverable   = attempt.Recoverable,
                    MessageIntent = attempt.MessageIntent,
                };

                if (!String.IsNullOrWhiteSpace(attempt.ReplyToAddress))
                {
                    transportMessage.ReplyToAddress = Address.Parse(attempt.ReplyToAddress);
                }

                failedMessage.Status = FailedMessageStatus.RetryIssued;

                Forwarder.Send(transportMessage, message.TargetEndpointAddress);
            }

            Bus.Publish <MessageSubmittedForRetry>(m => m.FailedMessageId = message.FailedMessageId);
        }
示例#3
0
        public TransportMessage IssueRetry(DateTime requestedAt)
        {
            var rawMessage = new TransportMessage(MessageId, Headers.Where(kv => !KeysToRemoveWhenRetryingAMessage.Contains(kv.Key)).ToDictionary(kv => kv.Key, kv => kv.Value))
            {
                Body           = BodyRaw,
                CorrelationId  = CorrelationId,
                Recoverable    = Recoverable,
                MessageIntent  = MessageIntent,
                ReplyToAddress = Address.Parse(ReplyToAddress)
            };

            Status = MessageStatus.RetryIssued;

            History.Add(new HistoryItem
            {
                Action = "RetryIssued",
                Time   = requestedAt
            });

            return(rawMessage);
        }
示例#4
0
        Task StageMessage(FailedMessage message, string stagingId)
        {
            message.Status = FailedMessageStatus.RetryIssued;

            var attempt = message.ProcessingAttempts.Last();

            var headersToRetryWith = attempt.Headers.Where(kv => !KeysToRemoveWhenRetryingAMessage.Contains(kv.Key))
                                     .ToDictionary(kv => kv.Key, kv => kv.Value);

            var addressOfFailingEndpoint = attempt.FailureDetails.AddressOfFailingEndpoint;

            var redirect = redirects[addressOfFailingEndpoint];

            if (redirect != null)
            {
                addressOfFailingEndpoint = redirect.ToPhysicalAddress;
            }

            headersToRetryWith["ServiceControl.TargetEndpointAddress"]   = addressOfFailingEndpoint;
            headersToRetryWith["ServiceControl.Retry.UniqueMessageId"]   = message.UniqueMessageId;
            headersToRetryWith["ServiceControl.Retry.StagingId"]         = stagingId;
            headersToRetryWith["ServiceControl.Retry.Attempt.MessageId"] = attempt.MessageId;

            corruptedReplyToHeaderStrategy.FixCorruptedReplyToHeader(headersToRetryWith);

            var transportMessage = new OutgoingMessage(message.Id, headersToRetryWith, emptyBody);

            transportMessage.Headers[Headers.MessageIntent] = attempt.MessageIntent.ToString();
            if (attempt.Recoverable)
            {
                transportMessage.Headers[Headers.NonDurableMessage] = true.ToString();
            }

            if (attempt.CorrelationId != null)
            {
                transportMessage.Headers[Headers.CorrelationId] = attempt.CorrelationId;
            }

            return(sender.Dispatch(new TransportOperations(new TransportOperation(transportMessage, new UnicastAddressTag(returnToSender.InputAddress))), transaction, contextBag));
        }