public RetryMessages() { Post["/errors/{messageid}/retry"] = parameters => { var failedMessageId = parameters.MessageId; if (string.IsNullOrEmpty(failedMessageId)) { return(HttpStatusCode.BadRequest); } Bus.SendLocal <RetryMessage>(m => { m.FailedMessageId = failedMessageId; }); return(HttpStatusCode.Accepted); }; Post["/errors/retry"] = _ => { var ids = this.Bind <List <string> >(); if (ids.Any(string.IsNullOrEmpty)) { return(HttpStatusCode.BadRequest); } foreach (var id in ids) { var request = new RetryMessage { FailedMessageId = id }; Bus.SendLocal(request); } return(HttpStatusCode.Accepted); }; Post["/errors/retry/all"] = _ => { var request = new RequestRetryAll(); Bus.SendLocal(request); return(HttpStatusCode.Accepted); }; Post["/errors/{name}/retry/all"] = parameters => { var request = new RequestRetryAll { Endpoint = parameters.name }; Bus.SendLocal(request); return(HttpStatusCode.Accepted); }; }
public void PublishOnRetryExchange(Channel channel, T message, RetryInformations retryInformations) { List <int> delays = _messageBrokerConfiguration.DelaysInMsBetweenEachRetry; int delay = 0; if (delays.Count >= retryInformations.NumberOfRetry) { delay = delays[retryInformations.NumberOfRetry]; } else { delay = delays.Last(); } retryInformations.NumberOfRetry++; RetryMessage <T> retryMessage = new RetryMessage <T> { OriginalMessage = message, RetryInformations = retryInformations }; string bindingValue = $"{channel.Value}.{delay}"; using (var publisher = _messagingService.GetPublisher($"{_messageBrokerConfiguration.BusName}.{RetryStrategyConfiguration.RetryExchangeSuffix}", true)) { TryPublishWithBrokerAcknowledgement(publisher, bindingValue, JsonConvert.SerializeObject(retryMessage)); } }
public void Handle(RetryMessage message) { //do not allow retries if we have other retries in progress if (Data.RetryAttempts.Any(a => !a.Completed)) { return; } var attemptToRetry = Data.ProcessingAttempts.Last(); var retryId = Guid.NewGuid(); Data.RetryAttempts.Add(new FailedMessagePolicyData.RetryAttempt { Id = retryId, FailedProcessingAttemptId = attemptToRetry.Id }); Bus.SendLocal(new PerformRetry { FailedMessageId = Data.FailedMessageId, TargetEndpointAddress = Data.ProcessingAttempts.Last().AddressOfFailingEndpoint, RetryId = retryId }); }
public void Handle(RetryMessage message) { var msg = Rows.FirstOrDefault(x => x.Id == message.Id); if (msg != null) { msg.Status = MessageStatus.RetryIssued; } }
public void OnMessageReceived(EventHandler <T> callback, IMessagingEvent messagingEvent) { RetryMessage <T> retryMessage = JsonConvert.DeserializeObject <RetryMessage <T> >(messagingEvent.Message.GetBody()); retryMessage.OriginalMessage.DeliveryTag = EncodeDeliveryTag(messagingEvent.DeliveryTag); RetryInformations.Add(retryMessage.OriginalMessage.DeliveryTag, retryMessage.RetryInformations); callback(this, retryMessage.OriginalMessage); }
public RetryMessages() { Post["/errors/{messageid}/retry"] = parameters => { var failedMessageId = parameters.MessageId; if (string.IsNullOrEmpty(failedMessageId)) { return HttpStatusCode.BadRequest; } Bus.SendLocal<RetryMessage>(m => { m.FailedMessageId = failedMessageId; }); return HttpStatusCode.Accepted; }; Post["/errors/retry"] = _ => { var ids = this.Bind<List<string>>(); if (ids.Any(string.IsNullOrEmpty)) { return HttpStatusCode.BadRequest; } foreach (var id in ids) { var request = new RetryMessage { FailedMessageId = id }; Bus.SendLocal(request); } return HttpStatusCode.Accepted; }; Post["/errors/retry/all"] = _ => { var request = new RequestRetryAll(); Bus.SendLocal(request); return HttpStatusCode.Accepted; }; Post["/errors/{name}/retry/all"] = parameters => { var request = new RequestRetryAll { Endpoint = parameters.name }; Bus.SendLocal(request); return HttpStatusCode.Accepted; }; }
internal void PublishOnErrorExchange(Channel channel, T message, RetryInformations technicalInformations) { string errorChanel = $"{channel.Value}.error"; RetryMessage <T> retryMessage = new RetryMessage <T> { OriginalMessage = message, RetryInformations = technicalInformations }; using (var publisher = _messagingService.GetPublisher($"{_messageBrokerConfiguration.BusName}.{RetryStrategyConfiguration.ErrorExchangeSuffix}", true)) { TryPublishWithBrokerAcknowledgement(publisher, errorChanel, JsonConvert.SerializeObject(retryMessage)); } }
public void Consumer_AcknowlegdeDeliveredMessage_ShouldRemoveMessageFromRetryInformationsList() { //Arrange RetryMessage <TestMessage> retryMessage = GetFilledRetryMessage(0); TestMessage testMessage = retryMessage.OriginalMessage; _consumer.RetryInformations.Add(testMessage.DeliveryTag, retryMessage.RetryInformations); //Act _consumer.AcknowlegdeDeliveredMessage(new Channel(""), testMessage); //Assert Assert.True(!_consumer.RetryInformations.ContainsKey(testMessage.DeliveryTag)); }
public void Handle(RequestRetryAll message) { var query = Session.Query <FailedMessageViewIndex.SortAndFilterOptions, FailedMessageViewIndex>(); if (message.Endpoint != null) { query = query.Where(fm => fm.ReceivingEndpointName == message.Endpoint); } using (var ie = Session.Advanced.Stream(query.OfType <FailedMessage>())) { while (ie.MoveNext()) { var retryMessage = new RetryMessage { FailedMessageId = ie.Current.Document.UniqueMessageId }; Bus.SendLocal(retryMessage); } } }
public void Consumer_OnMessageReceived_ShouldCallCallbackWithOriginalMessage() { //Arrange RetryMessage <TestMessage> messageInBody = GetFilledRetryMessage(0); Mock <IMessagingEvent> mockMessagingEvent = new Mock <IMessagingEvent>(); mockMessagingEvent.Setup(p => p.Message.GetBody()).Returns(JsonConvert.SerializeObject(messageInBody)); bool callbackCalled = false; TestMessage deliveredMessageFromCallback = null; //Act _consumer.OnMessageReceived((object sender, TestMessage deliveredMessage) => { callbackCalled = true; deliveredMessageFromCallback = deliveredMessage; } , mockMessagingEvent.Object); //Assert Assert.True(callbackCalled); Assert.True(_consumer.RetryInformations.ContainsKey(deliveredMessageFromCallback.DeliveryTag)); }
public Task Handle(RetryMessage message, IMessageHandlerContext context) { return(Retries.StartRetryForSingleMessage(message.FailedMessageId)); }
public void Handle(RetryMessage message) { Retries.StageRetryByUniqueMessageIds(message.FailedMessageId, RetryType.SingleMessage, new[] { message.FailedMessageId }, DateTime.UtcNow); }
public void Handle(RetryMessage message) { Retries.StartRetryForSingleMessage(message.FailedMessageId); }