Skip to content

Commit 17d7246

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

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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: 3 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' => null,
4344
'auto_setup' => true,
4445
'access_key' => null,
4546
'secret_key' => null,
@@ -137,6 +138,7 @@ public static function fromDsn(#[\SensitiveParameter] string $dsn, array $option
137138
'poll_timeout' => $options['poll_timeout'],
138139
'visibility_timeout' => null !== $options['visibility_timeout'] ? (int) $options['visibility_timeout'] : null,
139140
'delete_on_rejection' => filter_var($options['delete_on_rejection'], \FILTER_VALIDATE_BOOL),
141+
'retry_delay' => null !== $options['retry_delay'] ? (int) $options['retry_delay'] : null,
140142
'auto_setup' => filter_var($options['auto_setup'], \FILTER_VALIDATE_BOOL),
141143
'queue_name' => (string) $options['queue_name'],
142144
'queue_attributes' => $options['queue_attributes'],
@@ -323,7 +325,7 @@ public function reject(string $id): void
323325
$this->client->changeMessageVisibility([
324326
'QueueUrl' => $this->getQueueUrl(),
325327
'ReceiptHandle' => $id,
326-
'VisibilityTimeout' => $this->configuration['visibility_timeout'] ?? 30,
328+
'VisibilityTimeout' => $this->configuration['retry_delay'] ?? $this->configuration['visibility_timeout'] ?? 30,
327329
]);
328330
}
329331
}

0 commit comments

Comments
 (0)