public void ProcessSentMessage(string name, string specificRoute, object obj, IDictionary <string, object> headers, string exchangeName) { if (headers == null || !headers.ContainsKey(RetryConstants.RetryMessageIdKey)) { this.logger.Error("Null headers or no RetryMessageId"); return; } var retryMessageId = ProcessRetryMessageId(headers); this.attemptRepository.DeleteNotSentAttemptByRetryId(retryMessageId); var succeededAttempt = new SendAttemptEntity() { CreateDate = DateTime.UtcNow, Id = Guid.NewGuid(), RetryMessageId = retryMessageId, MessageHeadersJson = JsonConvert.SerializeObject(headers), MessageJson = JsonConvert.SerializeObject(obj), Name = name, SpecificRoute = specificRoute, ExchangeName = exchangeName, Status = SendAttemptEntity.AttemptStatus.Sent }; this.attemptRepository.SaveAttempt(succeededAttempt); }
public void ProcessFailedMessage(string name, string specificRoute, object obj, IDictionary <string, object> headers, string exchangeName) { var retryMessageId = ProcessRetryMessageId(headers); var messageJson = JsonConvert.SerializeObject(obj); var sendAttempts = this.attemptRepository.GetAttemptsByRetryId(retryMessageId); var skipRetry = false; var retryCount = sendAttempts?.Count(x => x.Status == SendAttemptEntity.AttemptStatus.NotSent); if (retryCount > this.maxAttemptsCount) { this.logger.Error("Skip trying republish - max attempts count exceeded."); //LOG THE MESSAGE this.attemptRepository.DeleteNotSentAttemptByRetryId(retryMessageId); skipRetry = true; } var succeededAttempt = new SendAttemptEntity() { CreateDate = DateTime.UtcNow, Id = Guid.NewGuid(), RetryMessageId = retryMessageId, MessageHeadersJson = JsonConvert.SerializeObject(headers), MessageJson = messageJson, Name = name, SpecificRoute = specificRoute, ExchangeName = exchangeName, Status = SendAttemptEntity.AttemptStatus.NotSent }; this.attemptRepository.SaveAttempt(succeededAttempt); if (skipRetry) { return; } var notSentAttemptEntity = new NotSentAttemptEntity() { CreateDate = DateTime.UtcNow, Id = Guid.NewGuid(), RetryMessageId = retryMessageId, MessageHeadersJson = JsonConvert.SerializeObject(headers), MessageJson = messageJson, Name = name, SpecificRoute = specificRoute, ExchangeName = exchangeName, MessageType = GetMessageType(obj) }; this.attemptRepository.SaveNotSentAttempt(notSentAttemptEntity); }
public Guid SaveAttempt(SendAttemptEntity entity) { this.dataProvider.Mapper.Update(entity); return(entity.Id); }