Skip to content

Commit b43ac84

Browse files
committed
Keep track of the declared queues inside RabbitMQ. So we won't check unnecessary times.
1 parent 5b8508b commit b43ac84

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/Queue/RabbitMQQueue.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,20 @@ public function deleteExchange(string $name, bool $unused = false): void
399399
*/
400400
public function isQueueExists(string $name = null): bool
401401
{
402+
$queueName = $this->getQueue($name);
403+
404+
if ($this->isQueueDeclared($queueName)) {
405+
return true;
406+
}
407+
402408
try {
403409
// create a temporary channel, so the main channel will not be closed on exception
404410
$channel = $this->createChannel();
405-
$channel->queue_declare($this->getQueue($name), true);
411+
$channel->queue_declare($queueName, true);
406412
$channel->close();
407413

414+
$this->queues[] = $queueName;
415+
408416
return true;
409417
} catch (AMQPProtocolChannelException $exception) {
410418
if ($exception->amqp_reply_code === 404) {
@@ -451,6 +459,9 @@ public function deleteQueue(string $name, bool $if_unused = false, bool $if_empt
451459
return;
452460
}
453461

462+
$idx = array_search($name, $this->queues);
463+
unset($this->queues[$idx]);
464+
454465
$this->getChannel()->queue_delete($name, $if_unused, $if_empty);
455466
}
456467

0 commit comments

Comments
 (0)