From 8885bc2eb9bae142e3594cbdf502dfad7656f502 Mon Sep 17 00:00:00 2001 From: Mark Joshua Tolentino Fajardo Date: Mon, 27 Jan 2025 10:57:59 +0800 Subject: [PATCH 1/3] [EasyNotification] Update SqsQueueTransport.php to handle FIFO queues --- .../EasyNotification/src/Queue/SqsQueueTransport.php | 12 +++++++++++- .../tests/NotificationClientTest.php | 2 ++ .../tests/Queue/SqsQueueTransportTest.php | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/EasyNotification/src/Queue/SqsQueueTransport.php b/packages/EasyNotification/src/Queue/SqsQueueTransport.php index 9fcde8ad84..5f19b4f429 100644 --- a/packages/EasyNotification/src/Queue/SqsQueueTransport.php +++ b/packages/EasyNotification/src/Queue/SqsQueueTransport.php @@ -7,6 +7,7 @@ use Aws\Sqs\SqsClient; use EonX\EasyNotification\Interfaces\QueueMessageInterface; use EonX\EasyNotification\Interfaces\QueueTransportInterface; +use Symfony\Component\Uid\Uuid; final class SqsQueueTransport implements QueueTransportInterface { @@ -22,10 +23,19 @@ public function __construct(SqsClient $sqs) public function send(QueueMessageInterface $queueMessage): void { + $queueUrl = $queueMessage->getQueueUrl(); + + if (\str_ends_with($queueUrl, '.fifo')) { + $messageDeduplicationId = (string)Uuid::v4(); + $messageGroupId = (string)Uuid::v4(); + } + $this->sqs->sendMessage([ - 'QueueUrl' => $queueMessage->getQueueUrl(), + 'QueueUrl' => $queueUrl, 'MessageAttributes' => $this->formatHeaders($queueMessage->getHeaders()), 'MessageBody' => $queueMessage->getBody(), + 'MessageDeduplicationId' => $messageDeduplicationId ?? null, + 'MessageGroupId' => $messageGroupId ?? null, ]); } diff --git a/packages/EasyNotification/tests/NotificationClientTest.php b/packages/EasyNotification/tests/NotificationClientTest.php index 04f2d49d90..ecc3986941 100644 --- a/packages/EasyNotification/tests/NotificationClientTest.php +++ b/packages/EasyNotification/tests/NotificationClientTest.php @@ -118,6 +118,8 @@ public function testSend(): void ], ], 'MessageBody' => '{"body":"{\"name\":\"nathan\"}","topics":["topic"]}', + 'MessageDeduplicationId' => null, + 'MessageGroupId' => null, ]; self::assertEquals($expected, $sqsClientStub->getCalls()[0]); diff --git a/packages/EasyNotification/tests/Queue/SqsQueueTransportTest.php b/packages/EasyNotification/tests/Queue/SqsQueueTransportTest.php index ce9dff7a47..b6149d8155 100644 --- a/packages/EasyNotification/tests/Queue/SqsQueueTransportTest.php +++ b/packages/EasyNotification/tests/Queue/SqsQueueTransportTest.php @@ -30,6 +30,8 @@ public function testSend(): void ], ], 'MessageBody' => 'my-body', + 'MessageDeduplicationId' => null, + 'MessageGroupId' => null, ]; self::assertEquals($expected, $stub->getCalls()[0]); From b72bfa2d496aec32d4fd7a2bf8f22ca6dc7ec4f5 Mon Sep 17 00:00:00 2001 From: Mark Joshua Tolentino Fajardo Date: Mon, 27 Jan 2025 12:55:18 +0800 Subject: [PATCH 2/3] [EasyNotification] Update SqsQueueTransport.php to handle FIFO queues: Add tests --- .../tests/Queue/SqsQueueTransportTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/EasyNotification/tests/Queue/SqsQueueTransportTest.php b/packages/EasyNotification/tests/Queue/SqsQueueTransportTest.php index b6149d8155..d1f77d8d35 100644 --- a/packages/EasyNotification/tests/Queue/SqsQueueTransportTest.php +++ b/packages/EasyNotification/tests/Queue/SqsQueueTransportTest.php @@ -36,4 +36,19 @@ public function testSend(): void self::assertEquals($expected, $stub->getCalls()[0]); } + + public function testSendFifo(): void + { + $queueUrl = 'https://sqs.my-queue.fifo'; + $stub = new SqsClientStub(); + $queueMessage = (new QueueMessage()) + ->addHeader('my-header', 'my-value') + ->setBody('my-body') + ->setQueueUrl($queueUrl); + + (new SqsQueueTransport($stub))->send($queueMessage); + + self::assertNotNull($stub->getCalls()[0]['MessageDeduplicationId']); + self::assertNotNull($stub->getCalls()[0]['MessageGroupId']); + } } From f28054fbd514b11b36d6e49af255119c28c05970 Mon Sep 17 00:00:00 2001 From: Mark Joshua Tolentino Fajardo Date: Tue, 28 Jan 2025 07:52:30 +0800 Subject: [PATCH 3/3] [EasyNotification] Update SqsQueueTransport.php to handle FIFO queues: Require symfony/uid --- packages/EasyNotification/composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/EasyNotification/composer.json b/packages/EasyNotification/composer.json index 0acc47a622..c52563b653 100644 --- a/packages/EasyNotification/composer.json +++ b/packages/EasyNotification/composer.json @@ -8,7 +8,8 @@ "aws/aws-sdk-php": "^3.134", "eonx-com/easy-utils": "^4.6", "nette/utils": "^3.1", - "symfony/http-client": "^5.4 || ^6.0" + "symfony/http-client": "^5.4 || ^6.0", + "symfony/uid": "^5.4 || ^6.0" }, "require-dev": { "phpunit/phpunit": "^9.5 || ^10.0",