mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
fix(sqs): return MD5 of current request on FIFO dedup replay (#786)
* fix(sqs): return MD5 of current request on FIFO dedup replay On a duplicate SendMessage within the 5-minute FIFO dedup window Floci returned the original message verbatim, including its cached MD5OfMessageBody and MD5OfMessageAttributes. AWS SDK clients validate those MD5s against the body and attributes they sent, so any time the second send differed from the first (or even when the first send had different attribute keys than the second's body alone) the SDK threw "MD5 returned by SQS does not match the calculation on the original request" and never delivered the message. AWS itself returns the original MessageId and SequenceNumber on dedup, but recomputes MD5s from the current request so the validation round-trips. Floci now does the same. A new SDK-driven integration test (sqs Java SDK at test scope) covers the dedup-replay case plus several standard/FIFO/binary/custom-type-name MD5 round-trips. Refs #768. * test(sqs): tighten dedup-replay MD5 test and drop redundant @Inject Address review feedback on #786: - Assert the second SendMessage returns the same MessageId and SequenceNumber as the first, so the test would catch a regression that silently disabled dedup (in which case the MD5 round-trip would also pass for the wrong reason). - Drop the redundant @Inject on the @ConfigProperty-injected field, matching the convention used in other Floci integration tests. * test(sqs): move FIFO MD5 SDK tests to compatibility-tests/sdk-test-java Address maintainer review on #786: - Drop the software.amazon.awssdk:sqs test-scope dependency from the main module's pom.xml. - Move SqsSdkMd5IntegrationTest to the compatibility-tests/sdk-test-java module as SqsMd5Test, where the existing AWS SDK v2 compatibility suite already lives. The test now follows that module's conventions (TestFixtures.sqsClient, AssertJ, lowerCamelCase method names, queue cleanup) and exercises the same scenarios: standard / FIFO / fair MD5 parity, binary and custom-type-name attributes, and the dedup-replay case that asserts the second SendMessage returns the original MessageId and SequenceNumber.
This commit is contained in:
1 parent
6b2c081f0b
commit
734e318278
2 files changed
+210
-2
No files matched your search
@@ -403,10 +403,22 @@ public class SqsService {
|
||||
Instant previous = dedupMap.putIfAbsent(dedupId, expiry);
|
||||
persistDedup(storageKey);
|
||||
if (previous != null && Instant.now().isBefore(previous)) {
|
||||
// Duplicate within window — return the original message idempotently
|
||||
// Duplicate within window — keep the original messageId and
|
||||
// sequenceNumber but compute response MD5s from this request's
|
||||
// body and attributes, otherwise SDK clients (which validate
|
||||
// MD5 against what they sent) reject the response.
|
||||
Message existing = getOrCreateQueue(storageKey).findByDeduplicationId(dedupId);
|
||||
if (existing != null) {
|
||||
return existing;
|
||||
Message response = new Message(body);
|
||||
response.setMessageId(existing.getMessageId());
|
||||
response.setMessageGroupId(messageGroupId);
|
||||
response.setMessageDeduplicationId(dedupId);
|
||||
response.setSequenceNumber(existing.getSequenceNumber());
|
||||
if (messageAttributes != null && !messageAttributes.isEmpty()) {
|
||||
response.getMessageAttributes().putAll(messageAttributes);
|
||||
response.updateMd5OfMessageAttributes();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user