Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
Adding support for delayed messages on SqsBatchedDispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan-hickey-cko authored and Jonathan-hickey-cko committed Apr 8, 2021
1 parent 9dd67fc commit e296897
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/OpenMessage.AWS.SQS/SqsBatchedDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@ public override async Task DispatchAsync(Message<T> 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,
Expand All @@ -81,14 +84,14 @@ public override async Task DispatchAsync(Message<T> message, CancellationToken c
}
}

private static int DelaySeconds(Message<T> message)
private static int? DelaySeconds(Message<T> message)
{
if (message is ISupportSendDelay delay && delay.SendDelay > TimeSpan.Zero)
{
return Math.Min(MaximumSqsDelaySeconds, (int) delay.SendDelay.TotalSeconds);
}

return 0;
return null;
}

private Dictionary<string, MessageAttributeValue> GetMessageProperties(Message<T> message)
Expand Down

0 comments on commit e296897

Please sign in to comment.