Skip to content

Commit 5b8508b

Browse files
committed
extracted new channel lines to a method createChannel().
1 parent dd37cbf commit 5b8508b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/Queue/RabbitMQQueue.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function size($queue = null): int
8484
}
8585

8686
// create a temporary channel, so the main channel will not be closed on exception
87-
$channel = $this->getConnection()->channel();
87+
$channel = $this->createChannel();
8888
[, $size] = $channel->queue_declare($queue, true);
8989
$channel->close();
9090

@@ -277,7 +277,7 @@ public function setConnection(AbstractConnection $connection): RabbitMQQueue
277277
public function getChannel($forceNew = false): AMQPChannel
278278
{
279279
if (! $this->channel || $forceNew) {
280-
$this->channel = $this->getConnection()->channel();
280+
$this->channel = $this->createChannel();
281281
}
282282

283283
return $this->channel;
@@ -327,7 +327,7 @@ public function isExchangeExists(string $exchange): bool
327327

328328
try {
329329
// create a temporary channel, so the main channel will not be closed on exception
330-
$channel = $this->getConnection()->channel();
330+
$channel = $this->createChannel();
331331
$channel->exchange_declare($exchange, '', true);
332332
$channel->close();
333333

@@ -401,7 +401,7 @@ public function isQueueExists(string $name = null): bool
401401
{
402402
try {
403403
// create a temporary channel, so the main channel will not be closed on exception
404-
$channel = $this->getConnection()->channel();
404+
$channel = $this->createChannel();
405405
$channel->queue_declare($this->getQueue($name), true);
406406
$channel->close();
407407

@@ -476,7 +476,7 @@ public function bindQueue(string $queue, string $exchange, string $routingKey =
476476
public function purge(string $queue = null): void
477477
{
478478
// create a temporary channel, so the main channel will not be closed on exception
479-
$channel = $this->getConnection()->channel();
479+
$channel = $this->createChannel();
480480
$channel->queue_purge($this->getQueue($queue));
481481
$channel->close();
482482
}
@@ -733,4 +733,9 @@ protected function publishBatch(): void
733733
{
734734
$this->getChannel()->publish_batch();
735735
}
736+
737+
protected function createChannel(): AMQPChannel
738+
{
739+
return $this->getConnection()->channel();
740+
}
736741
}

0 commit comments

Comments
 (0)