Пример #1
0
 /// <summary>
 /// Failes a subscribed message
 /// </summary>
 /// <param name="context"></param>
 /// <param name="exception"></param>
 /// <returns></returns>
 public Task Fail(SubscribedContext context, Exception exception)
 {
     context.MessageData.Retries++;
     context.MessageData.NotBefore    = _clock.UtcNow.AddSeconds(5 * context.MessageData.Retries); // Wait longer between retries.
     context.Headers.ExceptionDetails = exception.ToString();
     context.MessageData.Headers      = _serializer.SerializeHeaders(context.Headers);
     if (context.MessageData.Retries >= MaxRetries)
     {
         _log.Error($"Message {context.MessageData.MessageId} exceeded max retries ({MaxRetries}) and has failed.");
         context.MessageData.Failed = _clock.UtcNow;
         _counters.FailMessage();
         return(_dataAccess.FailMessage(context.MessageData));
     }
     else
     {
         _log.Error($"Message {context.MessageData.MessageId} will be retried at {context.MessageData.NotBefore}.");
         _counters.RetryMessage();
         return(_dataAccess.Update(context.MessageData));
     }
 }