Browse Source

rename configuration options FailedCallback to FailedThresholdCallback

undefined
Savorboard 6 years ago
parent
commit
bfa283e3f8
2 changed files with 33 additions and 28 deletions
  1. +2
    -2
      src/DotNetCore.CAP/CAP.Options.cs
  2. +31
    -26
      src/DotNetCore.CAP/Processor/IProcessor.NeedRetry.cs

+ 2
- 2
src/DotNetCore.CAP/CAP.Options.cs View File

@@ -58,9 +58,9 @@ namespace DotNetCore.CAP
public int FailedRetryInterval { get; set; }

/// <summary>
/// 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 <see cref="FailedRetryCount"/> times.
/// </summary>
public Action<MessageType, string, string> FailedCallback { get; set; }
public Action<MessageType, string, string> FailedThresholdCallback { get; set; }

/// <summary>
/// The number of message retries, the retry will stop when the threshold is reached.


+ 31
- 26
src/DotNetCore.CAP/Processor/IProcessor.NeedRetry.cs View File

@@ -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();


Loading…
Cancel
Save