Skip to content

Commit

Permalink
https://www.workerman.net/q/11912
Browse files Browse the repository at this point in the history
  • Loading branch information
chaz6chez committed Nov 22, 2023
1 parent 0e9d4be commit 09c58f7
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Client extends \Bunny\Async\Client
* "user" => "guest",
* "password" => "guest",
* "timeout" => 10,
* "restart_interval" => 0,
* "heartbeat" => 60,
* "heartbeat_callback" => function(){}
* ] {@see AbstractClient::__construct()} and {@see \Workerman\RabbitMQ\Client::authResponse()}
Expand Down Expand Up @@ -213,8 +214,20 @@ public function disconnect($replyCode = 0, $replyText = "")
$this->eventLoop->del($this->getStream(), EventInterface::EV_READ);
$this->closeStream();
$this->init();
if($replyCode !== 0){
Worker::stopAll(0,"RabbitMQ client disconnected: [{$replyCode}] {$replyText}");
if ($replyCode !== 0) {
if (($restartInterval = $this->options['restart_interval'] ?? 0) > 0) {
Worker::log("RabbitMQ client will restart in $restartInterval seconds. ");
$this->eventLoop->add(
$restartInterval,
EventInterface::EV_TIMER_ONCE,
function () use ($replyCode, $replyText, $restartInterval) {
Worker::stopAll(0,"RabbitMQ client disconnected: [{$replyCode}] {$replyText}");
}
);
return null;
} else {
Worker::stopAll(0,"RabbitMQ client disconnected: [{$replyCode}] {$replyText}");
}
}
return $this;
});
Expand Down

0 comments on commit 09c58f7

Please sign in to comment.