예제 #1
0
        private void Store(string uniqueMessageId, FailedMessage.ProcessingAttempt processingAttempt, List <FailedMessage.FailureGroup> groups)
        {
            var documentId = FailedMessage.MakeDocumentId(uniqueMessageId);

            store.DatabaseCommands.Patch(documentId,
                                         new[]
            {
                new PatchRequest
                {
                    Name  = nameof(FailedMessage.Status),
                    Type  = PatchCommandType.Set,
                    Value = (int)FailedMessageStatus.Unresolved
                },
                new PatchRequest
                {
                    Name  = nameof(FailedMessage.ProcessingAttempts),
                    Type  = PatchCommandType.Add,
                    Value = RavenJToken.FromObject(processingAttempt, Serializer)     // Need to specify serializer here because otherwise the $type for EndpointDetails is missing and this causes EventDispatcher to blow up!
                },
                new PatchRequest
                {
                    Name  = nameof(FailedMessage.FailureGroups),
                    Type  = PatchCommandType.Set,
                    Value = RavenJToken.FromObject(groups)
                }
            },
                                         new[]
            {
                new PatchRequest
                {
                    Name  = nameof(FailedMessage.UniqueMessageId),
                    Type  = PatchCommandType.Set,
                    Value = uniqueMessageId
                },
                new PatchRequest
                {
                    Name  = nameof(FailedMessage.Status),
                    Type  = PatchCommandType.Set,
                    Value = (int)FailedMessageStatus.Unresolved
                },
                new PatchRequest
                {
                    Name  = nameof(FailedMessage.ProcessingAttempts),
                    Type  = PatchCommandType.Add,
                    Value = RavenJToken.FromObject(processingAttempt, Serializer)     // Need to specify serilaizer here because otherwise the $type for EndpointDetails is missing and this causes EventDispatcher to blow up!
                },
                new PatchRequest
                {
                    Name  = nameof(FailedMessage.FailureGroups),
                    Type  = PatchCommandType.Set,
                    Value = RavenJToken.FromObject(groups)
                }
            }, JObjectMetadata
                                         );
        }
 public PreSplitScenario(FailedMessageStatus originalStatus)
 {
     UniqueMessageId             = DeterministicGuid.MakeId(MessageId, ReplyToAddress).ToString();
     OriginalFailedMessageStatus = originalStatus;
     FailedMessage = new FailedMessage()
     {
         Id = FailedMessage.MakeDocumentId(UniqueMessageId),
         UniqueMessageId    = UniqueMessageId,
         ProcessingAttempts = new List <FailedMessage.ProcessingAttempt>(),
         Status             = originalStatus,
         FailureGroups      = new List <FailedMessage.FailureGroup>()
     };
 }
            public void ProcessingAlwaysFailsForMessage(TransportMessage message, Exception e)
            {
                try
                {
                    var destination     = message.Headers["ServiceControl.TargetEndpointAddress"];
                    var messageUniqueId = message.Headers["ServiceControl.Retry.UniqueMessageId"];
                    Log.Warn($"Failed to send '{messageUniqueId}' message to '{destination}' for retry. Attempting to revert message status to unresolved so it can be tried again.", e);

                    using (var session = store.OpenSession())
                    {
                        var failedMessage = session.Load <FailedMessage>(FailedMessage.MakeDocumentId(messageUniqueId));
                        if (failedMessage != null)
                        {
                            failedMessage.Status = FailedMessageStatus.Unresolved;
                        }

                        var failedMessageRetry = session.Load <FailedMessageRetry>(FailedMessageRetry.MakeDocumentId(messageUniqueId));
                        if (failedMessageRetry != null)
                        {
                            session.Delete(failedMessageRetry);
                        }

                        session.SaveChanges();
                    }
                    string reason;
                    try
                    {
                        reason = e.GetBaseException().Message;
                    }
                    catch (Exception)
                    {
                        reason = "Failed to retrieve reason!";
                    }
                    domainEvents.Raise(new MessagesSubmittedForRetryFailed
                    {
                        Reason          = reason,
                        FailedMessageId = messageUniqueId,
                        Destination     = destination
                    });
                }
                catch (Exception ex)
                {
                    // If something goes wrong here we just ignore, not the end of the world!
                    Log.Error("A failure occurred when trying to handle a retry failure.", ex);
                }
                finally
                {
                    executeOnFailure();
                }
            }