Skip to content

[Messenger] fix manual amqp setup when autosetup disabled #40966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Connection
private $queuesOptions;
private $amqpFactory;
private $autoSetupExchange;
private $autoSetup;
private $autoSetupDelayExchange;

/**
* @var \AMQPChannel|null
Expand Down Expand Up @@ -114,7 +114,7 @@ public function __construct(array $connectionOptions, array $exchangeOptions, ar
'queue_name_pattern' => 'delay_%exchange_name%_%routing_key%_%delay%',
],
], $connectionOptions);
$this->autoSetupExchange = $this->autoSetup = $connectionOptions['auto_setup'] ?? true;
$this->autoSetupExchange = $this->autoSetupDelayExchange = $connectionOptions['auto_setup'] ?? true;
$this->exchangeOptions = $exchangeOptions;
$this->queuesOptions = $queuesOptions;
$this->amqpFactory = $amqpFactory ?? new AmqpFactory();
Expand Down Expand Up @@ -288,16 +288,16 @@ public function publish(string $body, array $headers = [], int $delayInMs = 0, A
{
$this->clearWhenDisconnected();

if ($this->autoSetupExchange) {
$this->setupExchangeAndQueues(); // also setup normal exchange for delayed messages so delay queue can DLX messages to it
}

if (0 !== $delayInMs) {
$this->publishWithDelay($body, $headers, $delayInMs, $amqpStamp);

return;
}

if ($this->autoSetupExchange) {
$this->setupExchangeAndQueues();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved this above so in setupDelay we only need to call setupDelayExchange

}

$this->publishOnExchange(
$this->exchange(),
$body,
Expand Down Expand Up @@ -356,8 +356,8 @@ private function publishOnExchange(\AMQPExchange $exchange, string $body, string

private function setupDelay(int $delay, ?string $routingKey)
{
if ($this->autoSetup) {
$this->setup(); // setup delay exchange and normal exchange for delay queue to DLX messages to
if ($this->autoSetupDelayExchange) {
$this->setupDelayExchange();
}

$queue = $this->createDelayQueue($delay, $routingKey);
Expand Down Expand Up @@ -450,11 +450,8 @@ public function nack(\AMQPEnvelope $message, string $queueName, int $flags = \AM

public function setup(): void
{
if ($this->autoSetupExchange) {
$this->setupExchangeAndQueues();
}
$this->getDelayExchange()->declareExchange();
$this->autoSetup = false;
$this->setupExchangeAndQueues();
$this->setupDelayExchange();
}

private function setupExchangeAndQueues(): void
Expand All @@ -470,6 +467,12 @@ private function setupExchangeAndQueues(): void
$this->autoSetupExchange = false;
}

private function setupDelayExchange(): void
{
$this->getDelayExchange()->declareExchange();
$this->autoSetupDelayExchange = false;
}

/**
* @return string[]
*/
Expand Down