Skip to content

Commit

Permalink
Optimized exchange declaration for consumer messages (#6716)
Browse files Browse the repository at this point in the history
  • Loading branch information
huangdijia authored Apr 26, 2024
1 parent 2436f4f commit 0d6e7ac
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,19 @@ public function consume(ConsumerMessageInterface $consumerMessage): void

try {
$channel = $connection->getConfirmChannel();
$exchange = $consumerMessage->getExchange();

$this->declare($consumerMessage, $channel);
$concurrent = $this->getConcurrent($consumerMessage->getPoolName());
if (! DeclaredExchanges::has($exchange)) {
try {
DeclaredExchanges::add($exchange);
$this->declare($consumerMessage, $channel);
} catch (Throwable $exception) {
DeclaredExchanges::remove($exchange);
throw $exception;
}
}

$concurrent = $this->getConcurrent($consumerMessage->getPoolName());
$maxConsumption = $consumerMessage->getMaxConsumption();
$currentConsumption = 0;

Expand Down

0 comments on commit 0d6e7ac

Please sign in to comment.