Skip to content

Commit ac9b312

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

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
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: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,13 +391,28 @@ public function testDoNotDeleteOnRejection()
391391
$expectedParams = [
392392
'QueueUrl' => $queueUrl = 'https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue',
393393
'ReceiptHandle' => $id = 'abc',
394-
'VisibilityTimeout' => $visibilityTimeout = 10,
394+
'VisibilityTimeout' => 0,
395395
];
396396

397397
$client = $this->createMock(SqsClient::class);
398398
$client->expects($this->once())->method('changeMessageVisibility')->with($expectedParams);
399399

400-
$connection = new Connection(['delete_on_rejection' => false, 'visibility_timeout' => $visibilityTimeout], $client, $queueUrl);
400+
$connection = new Connection(['delete_on_rejection' => false, 'visibility_timeout' => 30], $client, $queueUrl);
401+
$connection->reject($id);
402+
}
403+
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 = 5,
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, 'retry_delay' => $retryDelay], $client, $queueUrl);
401416
$connection->reject($id);
402417
}
403418

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)