From bdeef748cf2a22f504a4998fd85a7ed42d93da8a Mon Sep 17 00:00:00 2001 From: GurvanVgx <87641828+GurvanVgx@users.noreply.github.com> Date: Tue, 11 Oct 2022 12:38:51 +0200 Subject: [PATCH] [Messenger] Fix amqp socket lost Co-authored-by: Miguel Fernandez --- .../Messenger/Bridge/Amqp/Transport/Connection.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php b/src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php index e5a9d59eaa3bb..35fa87ca54a5a 100644 --- a/src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php +++ b/src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php @@ -102,6 +102,11 @@ class Connection */ private $amqpDelayExchange; + /** + * @var int + */ + private $lastActivityTime = 0; + public function __construct(array $connectionOptions, array $exchangeOptions, array $queuesOptions, AmqpFactory $amqpFactory = null) { if (!\extension_loaded('amqp')) { @@ -347,6 +352,8 @@ private function publishOnExchange(\AMQPExchange $exchange, string $body, string $attributes['delivery_mode'] = $attributes['delivery_mode'] ?? 2; $attributes['timestamp'] = $attributes['timestamp'] ?? time(); + $this->lastActivityTime = time(); + $exchange->publish( $body, $routingKey, @@ -510,6 +517,11 @@ static function (): bool { } ); } + + $this->lastActivityTime = time(); + } elseif (0 < ($this->connectionOptions['heartbeat'] ?? 0) && time() > $this->lastActivityTime + 2 * $this->connectionOptions['heartbeat']) { + $disconnectMethod = 'true' === ($this->connectionOptions['persistent'] ?? 'false') ? 'pdisconnect' : 'disconnect'; + $this->amqpChannel->getConnection()->{$disconnectMethod}(); } return $this->amqpChannel; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy