Skip to content

Commit 54123a9

Browse files
Merge remote-tracking branch 'remotes/github/MAGETWO-96342' into EPAM-PR-34
2 parents e98426b + 9794892 commit 54123a9

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

lib/internal/Magento/Framework/MessageQueue/MessageProcessor.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
*/
1313
class MessageProcessor implements MessageProcessorInterface
1414
{
15+
/**
16+
* Maximum number of transaction retries
17+
*/
18+
const MAX_TRANSACTION_RETRIES = 10;
19+
1520
/**
1621
* @var \Magento\Framework\MessageQueue\MessageStatusProcessor
1722
*/
@@ -22,6 +27,11 @@ class MessageProcessor implements MessageProcessorInterface
2227
*/
2328
private $resource;
2429

30+
/**
31+
* @var int
32+
*/
33+
private $retryCount = 0;
34+
2535
/**
2636
* @param MessageStatusProcessor $messageStatusProcessor
2737
* @param ResourceConnection $resource
@@ -53,8 +63,19 @@ public function process(
5363
} catch (ConnectionLostException $e) {
5464
$this->resource->getConnection()->rollBack();
5565
} catch (\Exception $e) {
66+
$retry = false;
5667
$this->resource->getConnection()->rollBack();
57-
$this->messageStatusProcessor->rejectMessages($queue, $messages);
68+
if (strpos($e->getMessage(), 'Error while sending QUERY packet') !== false
69+
&& $this->retryCount < self::MAX_TRANSACTION_RETRIES
70+
) {
71+
$retry = true;
72+
$this->retryCount++;
73+
$this->resource->closeConnection();
74+
$this->process($queue, $configuration, $messages, $messagesToAcknowledge, $mergedMessages);
75+
}
76+
if (!$retry) {
77+
$this->messageStatusProcessor->rejectMessages($queue, $messages);
78+
}
5879
}
5980
}
6081

0 commit comments

Comments
 (0)