Преглед изворни кода

Fix amazon sqs reject message bug

master
Savorboard пре 4 година
родитељ
комит
daf4efbf50
4 измењених фајлова са 60 додато и 4 уклоњено
  1. +48
    -2
      src/DotNetCore.CAP.AmazonSQS/AmazonSQSConsumerClient.cs
  2. +1
    -1
      src/DotNetCore.CAP.AmazonSQS/TopicNormalizer.cs
  3. +6
    -0
      src/DotNetCore.CAP/Internal/IConsumerRegister.Default.cs
  4. +5
    -1
      src/DotNetCore.CAP/Transport/MqLogType.cs

+ 48
- 2
src/DotNetCore.CAP.AmazonSQS/AmazonSQSConsumerClient.cs Прегледај датотеку

@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Amazon.SimpleNotificationService;
using Amazon.SimpleNotificationService.Model;
using Amazon.SQS;
@@ -103,12 +104,27 @@ namespace DotNetCore.CAP.AmazonSQS

public void Commit(object sender)
{
_sqsClient.DeleteMessageAsync(_queueUrl, (string)sender);
try
{
_sqsClient.DeleteMessageAsync(_queueUrl, (string)sender);
}
catch (InvalidIdFormatException ex)
{
InvalidIdFormatLog(ex.Message);
}
}

public void Reject(object sender)
{
_sqsClient.ChangeMessageVisibilityAsync(_queueUrl, (string)sender, 3000);
try
{
// Visible again in 3 seconds
_sqsClient.ChangeMessageVisibilityAsync(_queueUrl, (string)sender, 3);
}
catch (MessageNotInflightException ex)
{
MessageNotInflightLog(ex.Message);
}
}

public void Dispose()
@@ -162,5 +178,35 @@ namespace DotNetCore.CAP.AmazonSQS
}
}
}

#region private methods

private Task InvalidIdFormatLog(string exceptionMessage)
{
var logArgs = new LogMessageEventArgs
{
LogType = MqLogType.InvalidIdFormat,
Reason = exceptionMessage
};

OnLog?.Invoke(null, logArgs);

return Task.CompletedTask;
}

private Task MessageNotInflightLog(string exceptionMessage)
{
var logArgs = new LogMessageEventArgs
{
LogType = MqLogType.MessageNotInflight,
Reason = exceptionMessage
};

OnLog?.Invoke(null, logArgs);

return Task.CompletedTask;
}

#endregion
}
}

+ 1
- 1
src/DotNetCore.CAP.AmazonSQS/TopicNormalizer.cs Прегледај датотеку

@@ -2,7 +2,7 @@

namespace DotNetCore.CAP.AmazonSQS
{
public static class TopicNormalizer
internal static class TopicNormalizer
{
public static string NormalizeForAws(this string origin)
{


+ 6
- 0
src/DotNetCore.CAP/Internal/IConsumerRegister.Default.cs Прегледај датотеку

@@ -271,6 +271,12 @@ namespace DotNetCore.CAP.Internal
case MqLogType.ExceptionReceived:
_logger.LogError("AzureServiceBus subscriber received an error. --> " + logmsg.Reason);
break;
case MqLogType.InvalidIdFormat:
_logger.LogError("AmazonSQS subscriber delete inflight message failed, invalid id. --> " + logmsg.Reason);
break;
case MqLogType.MessageNotInflight:
_logger.LogError("AmazonSQS subscriber change message's visibility failed, message isn't in flight. --> " + logmsg.Reason);
break;
default:
throw new ArgumentOutOfRangeException();
}


+ 5
- 1
src/DotNetCore.CAP/Transport/MqLogType.cs Прегледај датотеку

@@ -18,7 +18,11 @@ namespace DotNetCore.CAP.Transport
ServerConnError,

//AzureServiceBus
ExceptionReceived
ExceptionReceived,

//Amazon SQS
InvalidIdFormat,
MessageNotInflight
}

public class LogMessageEventArgs : EventArgs


Loading…
Откажи
Сачувај