Skip to content

Commit c64f5ae

Browse files
committed
[Messenger] Remove configuration for redelivery_max_count
1 parent 20cddc3 commit c64f5ae

File tree

3 files changed

+13
-23
lines changed

3 files changed

+13
-23
lines changed

src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineReceiverTest.php

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,28 +75,18 @@ public function testOccursRetryableExceptionFromConnection()
7575
{
7676
$serializer = $this->createSerializer();
7777
$connection = $this->createMock(Connection::class);
78-
$connection->method('getConfiguration')->willReturn([
79-
'redelivery_max_count' => 3,
80-
]);
8178
$driverException = new PDOException(new \PDOException('Deadlock', 40001));
8279
$connection->method('get')->willThrowException(new DeadlockException('Deadlock', $driverException));
8380
$receiver = new DoctrineReceiver($connection, $serializer);
84-
$actualEnvelopes = $receiver->get();
85-
$this->assertSame([], $actualEnvelopes);
86-
}
87-
88-
public function testOccursRetryableExceptionAfterMaxCountFromConnection()
89-
{
90-
$serializer = $this->createSerializer();
91-
$connection = $this->createMock(Connection::class);
92-
$connection->method('getConfiguration')->willReturn([
93-
'redelivery_max_count' => 2,
94-
]);
95-
$driverException = new PDOException(new \PDOException('Deadlock', 40001));
96-
$connection->method('get')->willThrowException(new DeadlockException('Deadlock', $driverException));
97-
$receiver = new DoctrineReceiver($connection, $serializer);
98-
$actualEnvelopes = $receiver->get();
99-
$this->assertSame([], $actualEnvelopes);
81+
$this->assertSame([], $receiver->get());
82+
$this->assertSame([], $receiver->get());
83+
try {
84+
$receiver->get();
85+
} catch (TransportException $exception) {
86+
// skip, and retry
87+
}
88+
$this->assertSame([], $receiver->get());
89+
$this->assertSame([], $receiver->get());
10090
$this->expectException(TransportException::class);
10191
$receiver->get();
10292
}

src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class Connection
3636
'queue_name' => 'default',
3737
'redeliver_timeout' => 3600,
3838
'auto_setup' => true,
39-
'redelivery_max_count' => 3,
4039
];
4140

4241
/**
@@ -80,7 +79,6 @@ public static function buildConfiguration($dsn, array $options = [])
8079
$configuration = ['connection' => $components['host']];
8180
$configuration += $options + $query + self::DEFAULT_OPTIONS;
8281

83-
$configuration['redelivery_max_count'] = filter_var($configuration['redelivery_max_count'], FILTER_VALIDATE_INT);
8482
$configuration['auto_setup'] = filter_var($configuration['auto_setup'], FILTER_VALIDATE_BOOLEAN);
8583

8684
// check for extra keys in options

src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineReceiver.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
*/
3232
class DoctrineReceiver implements ReceiverInterface, MessageCountAwareInterface, ListableReceiverInterface
3333
{
34+
private const MAX_RETRIES = 3;
3435
private $retryingSafetyCounter = 0;
3536
private $connection;
3637
private $serializer;
@@ -50,10 +51,11 @@ public function get(): iterable
5051
$doctrineEnvelope = $this->connection->get();
5152
$this->retryingSafetyCounter = 0; // reset counter
5253
} catch (RetryableException $exception) {
53-
// Do nothing when RetryableException occurs less than "redelivery_max_count"
54+
// Do nothing when RetryableException occurs less than "MAX_RETRIES"
5455
// as it will likely be resolved on the next call to get()
5556
// Problem with concurrent consumers and database deadlocks
56-
if (++$this->retryingSafetyCounter >= $this->connection->getConfiguration()['redelivery_max_count']) {
57+
if (++$this->retryingSafetyCounter >= self::MAX_RETRIES) {
58+
$this->retryingSafetyCounter = 0; // reset counter
5759
throw new TransportException($exception->getMessage(), 0, $exception);
5860
}
5961

0 commit comments

Comments
 (0)