Skip to content

Commit 0d22b64

Browse files
authored
Merge pull request vyuldashev#87 from PrivateDev/declare-queue-exchange-once
declare exchange & queue one time only
2 parents 9f5ed92 + c50775b commit 0d22b64

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/VladimirYuldashev/LaravelQueueRabbitMQ/Queue/RabbitMQQueue.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ class RabbitMQQueue extends Queue implements QueueContract
2222
protected $channel;
2323

2424
protected $declareExchange;
25+
protected $declaredExchanges = [];
26+
2527
protected $declareBindQueue;
28+
protected $declaredBindQueue = [];
2629

2730
protected $defaultQueue;
2831
protected $configQueue;
@@ -172,7 +175,8 @@ private function declareQueue($name)
172175
$name = $this->getQueueName($name);
173176
$exchange = $this->configExchange['name'] ?: $name;
174177

175-
if ($this->declareExchange) {
178+
if ($this->declareExchange && ! in_array($exchange, $this->declaredExchanges)) {
179+
$this->declaredExchanges[] = $exchange;
176180
// declare exchange
177181
$this->channel->exchange_declare(
178182
$exchange,
@@ -183,7 +187,8 @@ private function declareQueue($name)
183187
);
184188
}
185189

186-
if ($this->declareBindQueue) {
190+
if ($this->declareBindQueue && ! in_array($name, $this->declaredBindQueue)) {
191+
$this->declaredBindQueue[] = $name;
187192
// declare queue
188193
$this->channel->queue_declare(
189194
$name,

0 commit comments

Comments
 (0)