From e29689731decb6d98c70a8cc346f6796503da126 Mon Sep 17 00:00:00 2001 From: Jonathan-hickey-cko Date: Thu, 8 Apr 2021 15:23:17 +0100 Subject: [PATCH] Adding support for delayed messages on SqsBatchedDispatcher --- src/OpenMessage.AWS.SQS/SqsBatchedDispatcher.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/OpenMessage.AWS.SQS/SqsBatchedDispatcher.cs b/src/OpenMessage.AWS.SQS/SqsBatchedDispatcher.cs index 3364a99..e36ff3e 100644 --- a/src/OpenMessage.AWS.SQS/SqsBatchedDispatcher.cs +++ b/src/OpenMessage.AWS.SQS/SqsBatchedDispatcher.cs @@ -56,10 +56,13 @@ public override async Task DispatchAsync(Message message, CancellationToken c { Id = Guid.NewGuid().ToString("N"), MessageAttributes = GetMessageProperties(message), - DelaySeconds = DelaySeconds(message), MessageBody = json }; + var delay = DelaySeconds(message); + if (delay.HasValue) + request.DelaySeconds = delay.Value; + var msg = new SendSqsMessageCommand { Message = request, @@ -81,14 +84,14 @@ public override async Task DispatchAsync(Message message, CancellationToken c } } - private static int DelaySeconds(Message message) + private static int? DelaySeconds(Message message) { if (message is ISupportSendDelay delay && delay.SendDelay > TimeSpan.Zero) { return Math.Min(MaximumSqsDelaySeconds, (int) delay.SendDelay.TotalSeconds); } - return 0; + return null; } private Dictionary GetMessageProperties(Message message)