Can you define a consumer command that only consumes a specific queue of a multi-queue transport?

1.3k Views Asked by At

I have the impression to miss something while implementing AMQP services with RabbitMQ and Symfony Messenger.

From a RabbitMQ perspective, consumers (also known as workers) consume from queues.

From the Symfony Messenger documentation, one "transport" is linked to one consumer. This is by design as shown by the command bin/console messenger:consume transport. So, for each "handler", you have to configure a dedicated transport in messenger.yaml to be able to allocate a specific number of processes (via Supervisor for instance in configuring the numprocs variable).

As stated, I found a way to configure that use case using 2 different transports. Yet, that looks a bit too complicated to me:

framework:
  messenger:
    transports:
      one_transport:
        dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
        options:
          exchange:
            name: my_exchange
            type: direct
          queues:
            one_queue:
              binding_keys:
                - one_binding_key
      another_transport:
        dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
        options:
          exchange:
            name: my_exchange
            type: direct
          queues:
            another_queue:
              binding_keys:
                - another_binding_key
    routing:
      'App\MessageBroker\Message\OneNotification': one_transport
      'App\MessageBroker\Message\AnotherNotification': another_transport
# In action 1
$this->dispatchMessage(
    new OneNotification(), [new AmqpStamp('one_binding_key')]
);

# Action 2
$this->dispatchMessage(
    new AnotherNotification(), [new AmqpStamp('another_binding_key')]
);
# SF consumer 1
[program:messenger-consume]
command=php bin/console messenger:consume one_transport
numprocs=4

# SF consumer 2
[program:messenger-consume]
command=php bin/console messenger:consume another_transport
numprocs=1

No other way to achieve this?

0

There are 0 best solutions below