diff --git a/src/DotNetCore.CAP/CAP.Options.cs b/src/DotNetCore.CAP/CAP.Options.cs
index 267a61f..05c0294 100644
--- a/src/DotNetCore.CAP/CAP.Options.cs
+++ b/src/DotNetCore.CAP/CAP.Options.cs
@@ -58,9 +58,9 @@ namespace DotNetCore.CAP
public int FailedRetryInterval { get; set; }
///
- /// We’ll invoke this call-back with message type,name,content when requeue failed message.
+ /// We’ll invoke this call-back with message type,name,content when retry failed (send or executed) messages equals times.
///
- public Action FailedCallback { get; set; }
+ public Action FailedThresholdCallback { get; set; }
///
/// The number of message retries, the retry will stop when the threshold is reached.
diff --git a/src/DotNetCore.CAP/Processor/IProcessor.NeedRetry.cs b/src/DotNetCore.CAP/Processor/IProcessor.NeedRetry.cs
index dbd2212..2f7b829 100644
--- a/src/DotNetCore.CAP/Processor/IProcessor.NeedRetry.cs
+++ b/src/DotNetCore.CAP/Processor/IProcessor.NeedRetry.cs
@@ -65,19 +65,6 @@ namespace DotNetCore.CAP.Processor
continue;
}
- if (!hasException)
- {
- try
- {
- _options.FailedCallback?.Invoke(MessageType.Publish, message.Name, message.Content);
- }
- catch (Exception ex)
- {
- hasException = true;
- _logger.LogWarning("Failed call-back method raised an exception:" + ex.Message);
- }
- }
-
using (var transaction = connection.CreateTransaction())
{
var result = await _publishExecutor.PublishAsync(message.Name, message.Content);
@@ -101,6 +88,21 @@ namespace DotNetCore.CAP.Processor
{
_logger.LogError($"The message still sent failed after {_options.FailedRetryCount} retries. We will stop retrying the message. " +
"MessageId:" + message.Id);
+ if (message.Retries == _options.FailedRetryCount)
+ {
+ if (!hasException)
+ {
+ try
+ {
+ _options.FailedThresholdCallback?.Invoke(MessageType.Publish, message.Name, message.Content);
+ }
+ catch (Exception ex)
+ {
+ hasException = true;
+ _logger.LogWarning("Failed call-back method raised an exception:" + ex.Message);
+ }
+ }
+ }
}
}
await transaction.CommitAsync();
@@ -124,19 +126,6 @@ namespace DotNetCore.CAP.Processor
continue;
}
- if (!hasException)
- {
- try
- {
- _options.FailedCallback?.Invoke(MessageType.Subscribe, message.Name, message.Content);
- }
- catch (Exception ex)
- {
- hasException = true;
- _logger.LogWarning("Failed call-back method raised an exception:" + ex.Message);
- }
- }
-
using (var transaction = connection.CreateTransaction())
{
var result = await _subscriberExecutor.ExecuteAsync(message);
@@ -160,6 +149,22 @@ namespace DotNetCore.CAP.Processor
{
_logger.LogError($"[Subscriber]The message still executed failed after {_options.FailedRetryCount} retries. " +
"We will stop retrying to execute the message. message id:" + message.Id);
+
+ if (message.Retries == _options.FailedRetryCount)
+ {
+ if (!hasException)
+ {
+ try
+ {
+ _options.FailedThresholdCallback?.Invoke(MessageType.Subscribe, message.Name, message.Content);
+ }
+ catch (Exception ex)
+ {
+ hasException = true;
+ _logger.LogWarning("Failed call-back method raised an exception:" + ex.Message);
+ }
+ }
+ }
}
}
await transaction.CommitAsync();