Pārlūkot izejas kodu

fix(sync producer): exception to disconnect

roiwk 1 gadu atpakaļ
vecāks
revīzija
8b9584e9a4
1 mainītis faili ar 3 papildinājumiem un 2 dzēšanām
  1. 3 2
      src/Producer.php

+ 3 - 2
src/Producer.php

@@ -119,10 +119,11 @@ class Producer
             $channel = $client->channel();
             $this->declare($channel, $routingOrQueue, $exchange, $exchangeType);
             $published = $channel->publish($data, $headers, $exchange, $routingOrQueue, $mandatory, $immediate);
-            $channel->close();
-            $client->disconnect();
         } catch (\Throwable $throwable) {
             $this->logger?->error('['.getmypid().']:'.$throwable->getMessage().PHP_EOL.$throwable->getTraceAsString(), [__CLASS__]);
+        } finally {
+            isset($channel) && $channel->close();
+            isset($client) && $client->disconnect();
         }
 
         return $published ?? false;