Skip to content

Commit 15e06fa

Browse files
committed
[Messenger] Add retry delay on amazon sqs
1 parent 9359b31 commit 15e06fa

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/Symfony/Component/Messenger/Bridge/AmazonSqs/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ CHANGELOG
44
7.4
55
---
66

7-
* Allow SQS to handle it's own retry/DLQ
7+
* Allow SQS to handle its own retry/DLQ
8+
* Add `retry_delay` option to configure the delay between retries when using SQS retry/DLQ handling
89

910
7.3
1011
---

src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/ConnectionTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,21 @@ public function testDoNotDeleteOnRejection()
401401
$connection->reject($id);
402402
}
403403

404+
public function testDoNotDeleteOnRejectionWithRetryDelay()
405+
{
406+
$expectedParams = [
407+
'QueueUrl' => $queueUrl = 'https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue',
408+
'ReceiptHandle' => $id = 'abc',
409+
'VisibilityTimeout' => $retryDelay = 0,
410+
];
411+
412+
$client = $this->createMock(SqsClient::class);
413+
$client->expects($this->once())->method('changeMessageVisibility')->with($expectedParams);
414+
415+
$connection = new Connection(['delete_on_rejection' => false, 'visibility_timeout' => 30, 'retry_delay' => $retryDelay], $client, $queueUrl);
416+
$connection->reject($id);
417+
}
418+
404419
public function testKeepaliveWithTooSmallTtl()
405420
{
406421
$client = $this->createMock(SqsClient::class);

src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/Connection.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Connection
4040
'poll_timeout' => 0.1,
4141
'visibility_timeout' => null,
4242
'delete_on_rejection' => true,
43+
'retry_delay' => 0,
4344
'auto_setup' => true,
4445
'access_key' => null,
4546
'secret_key' => null,
@@ -103,6 +104,7 @@ public function __destruct()
103104
* * poll_timeout: amount of seconds the transport should wait for new message
104105
* * visibility_timeout: amount of seconds the message won't be visible
105106
* * delete_on_rejection: Whether to delete message on rejection or allow SQS to handle retries. (Default: true).
107+
* * retry_delay: amount of seconds the message won't be visible before retry. (Default: 0).
106108
* * sslmode: Can be "disable" to use http for a custom endpoint
107109
* * auto_setup: Whether the queue should be created automatically during send / get (Default: true)
108110
* * debug: Log all HTTP requests and responses as LoggerInterface::DEBUG (Default: false)
@@ -137,6 +139,7 @@ public static function fromDsn(#[\SensitiveParameter] string $dsn, array $option
137139
'poll_timeout' => $options['poll_timeout'],
138140
'visibility_timeout' => null !== $options['visibility_timeout'] ? (int) $options['visibility_timeout'] : null,
139141
'delete_on_rejection' => filter_var($options['delete_on_rejection'], \FILTER_VALIDATE_BOOL),
142+
'retry_delay' => (int) $options['retry_delay'],
140143
'auto_setup' => filter_var($options['auto_setup'], \FILTER_VALIDATE_BOOL),
141144
'queue_name' => (string) $options['queue_name'],
142145
'queue_attributes' => $options['queue_attributes'],
@@ -323,7 +326,7 @@ public function reject(string $id): void
323326
$this->client->changeMessageVisibility([
324327
'QueueUrl' => $this->getQueueUrl(),
325328
'ReceiptHandle' => $id,
326-
'VisibilityTimeout' => $this->configuration['visibility_timeout'] ?? 30,
329+
'VisibilityTimeout' => $this->configuration['retry_delay'],
327330
]);
328331
}
329332
}

0 commit comments

Comments
 (0)