mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(sqs): derive the content-based deduplication ID with SHA-256 (#9526)
A FIFO queue with ContentBasedDeduplication derived the MessageDeduplicationId from an MD5 of the body, while AWS uses a SHA-256 hash of it, so ReceiveMessage returned a 32-character ID where AWS returns 64. The ID is now the body's SHA-256, as SNS FIFO topics already derive it.
This commit is contained in:
1 parent
646a3a5671
commit
537b57c381
2 files changed
+13
-1
No files matched your search
@@ -1074,7 +1074,7 @@ public class SqsService implements Resettable, ResourceProvider {
|
||||
String dedupId = messageDeduplicationId;
|
||||
if (dedupId == null || dedupId.isEmpty()) {
|
||||
if ("true".equalsIgnoreCase(queue.getAttributes().get("ContentBasedDeduplication"))) {
|
||||
dedupId = Digests.md5Hex(body.getBytes(StandardCharsets.UTF_8));
|
||||
dedupId = Digests.sha256Hex(body);
|
||||
} else {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"The queue should either have ContentBasedDeduplication enabled or " +
|
||||
|
||||
@@ -1195,6 +1195,18 @@ class SqsServiceTest {
|
||||
assertNotNull(msg.getMessageDeduplicationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void receiveMessageFromContentBasedFifoQueueExposesSha256OfBodyAsDeduplicationId() {
|
||||
String region = "eu-west-1";
|
||||
Queue queue = sqsService.createQueue("sha.fifo",
|
||||
Map.of("ContentBasedDeduplication", "true"), region);
|
||||
sqsService.sendMessage(queue.getQueueUrl(), "Hello FIFO", 0, "group1", null, region);
|
||||
List<Message> received = sqsService.receiveMessage(queue.getQueueUrl(), 1, 30, 0, region);
|
||||
assertEquals(1, received.size());
|
||||
assertEquals("b5e96aefb0edd6cda6902fa13329717f12231718298872fa7f6a822305b743dd",
|
||||
received.get(0).getMessageDeduplicationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void sendMessageToFifoQueueWithExplicitDedupId() {
|
||||
String region = "eu-west-1";
|
||||
|
||||
Reference in new issue
Block a user