Skip to content

Messenger - AMQP Extension - auto_setup:true leads to poor performance on RabbitMq consumers  #38092

@dorinelpna

Description

@dorinelpna

Symfony version(s) affected: 5.*
Description
The transport configuration - auto_setup: true (that is the default) will try to create the exchange, the queue(s) and try to bind them, for every message retrieved from the queue, leading to low get/acknowledge rate.

AmqpExt\Connection.php

 /**
     * Gets a message from the specified queue.
     *
     * @throws \AMQPException
     */
    public function get(string $queueName): ?\AMQPEnvelope
    {
        $this->clearWhenDisconnected();

        **if ($this->shouldSetup()) {
            $this->setupExchangeAndQueues();
        }**

Possible Solution

if ($this->shouldSetup() && !in_array($queueName, $this->setupQueues)) {
            $this->setupExchangeAndQueues();
            array_push($this->setupQueues, $queueName);
        }

This means $this->setupExchangeAndQueues() will be called only once when starting the consumer instance.

If queue / exchange are deleted while consumer is running

/**
    * Gets a message from the specified queue.
    *
    * @throws \AMQPException
    */
   public function get(string $queueName): ?\AMQPEnvelope
   {
    ..........
    } catch (\AMQPQueueException $e) {
           if (404 === $e->getCode() && $this->shouldSetup()) {

                $this->clearWhenDisconnected();
               // If we get a 404 for the queue, it means we need to set up the exchange & queue.
               $this->setupExchangeAndQueues();

               return $this->get($queueName);
           }

           throw $e;
       } 
........

Additional context
Not sure if there are any cases when this issue can occur.
This issue is very possible to occur when sending messages also.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions