Skip to content

Commit

Permalink
SQS Message handling update
Browse files Browse the repository at this point in the history
Ensure old messages are removed even if the target is a different service to prevent constant re-processing.  e.g. Bad message or service is offline.
  • Loading branch information
DavidWiseman committed Jun 25, 2024
1 parent df327fe commit d7b1639
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions DBADash/Messaging/SQSMessageProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,7 @@ private static bool ValidateMessageAttributes(Message message,string expectedAge
replySQS = string.Empty;
replyAgent = string.Empty;

if (!message.MessageAttributes.TryGetValue("DBADashToIdentifier", out var targetAgent))
{
reason = "Message does not contain a DBADashToIdentifier attribute.";
deleteMessage = false;
return false;
}
if (targetAgent.StringValue != expectedAgent)
{
reason = $"Message is not intended for this agent. Expected {expectedAgent} but received {targetAgent.StringValue}. This is expected when using a shared queue.";
notForThisAgent = true;
deleteMessage = false;
return false;
}

/* Remove old messages regardless of target service. This will prevent constant re-processing of old messages */
if (!message.Attributes.TryGetValue(MessageSystemAttributeName.SentTimestamp, out var sentTimestamp))
{
reason = "Message does not contain a SentTimestamp attribute.";
Expand All @@ -180,6 +167,21 @@ private static bool ValidateMessageAttributes(Message message,string expectedAge
return false;
}

if (!message.MessageAttributes.TryGetValue("DBADashToIdentifier", out var targetAgent))
{
reason = "Message does not contain a DBADashToIdentifier attribute.";
deleteMessage = false;
return false;
}
/* Might be using a shared queue. Keep the message. Visibility timeout adjusted to allow other service to pick up the message. */
if (targetAgent.StringValue != expectedAgent)
{
reason = $"Message is not intended for this agent. Expected {expectedAgent} but received {targetAgent.StringValue}. This is expected when using a shared queue.";
notForThisAgent = true;
deleteMessage = false;
return false;
}

if (!message.MessageAttributes.TryGetValue("MessageType", out var messageTypeAttribute))
{
reason = "Message does not contain a MessageType attribute.";
Expand Down

0 comments on commit d7b1639

Please sign in to comment.