Skip to content

[Messenger] Add --exclude-queues consume parameters #60979

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

Open
wants to merge 1 commit into
base: 7.4
Choose a base branch
from

Conversation

jbdelhommeau
Copy link
Contributor

@jbdelhommeau jbdelhommeau commented Jun 30, 2025

Q A
Branch? 7.4
Bug fix? no
New feature? yes
Deprecations? no
Docs symfony/symfony-docs#21165
License MIT

This PR adds a new --exclude-transports (shortcut -et) option to the messenger:consume command. This option allows users to exclude specific transports/receivers from being consumed when using the --all flag.

What it does and why it's needed:

  • When running messenger:consume --all, you may want to skip certain transports (example the failed transports) without having to list all the others manually. The new --exclude-transports option makes this possible.
  • This improves flexibility and usability for complex Messenger setups.

How it works:

php bin/console messenger:consume --all --exclude-transports=queues1 --exclude-transports=queues2

This will consume messages from all transports except queues1 and queues2.

Behavior:

  • The --exclude-queues option can only be used with --all. If used without --all, an InvalidOptionException is thrown.
  • If all queues are excluded, a RuntimeException is thrown to prevent running the command with no receivers.

Before:

  • No way to exclude specific receivers when using --all.

After:

  • You can now exclude queues with --exclude-transports when using --all.

Tests:

  • Unit tests have been added to cover the new option, its validation, and edge cases.

@jbdelhommeau
Copy link
Contributor Author

@Kocal 🎁

@jbdelhommeau jbdelhommeau force-pushed the messenger-exlude-receivers branch from 52da22d to 04d44be Compare June 30, 2025 12:34
@carsonbot carsonbot changed the title chore: add exclude-receivers consume parameters [Messenger] chore: add exclude-receivers consume parameters Jun 30, 2025
@nicolas-grekas nicolas-grekas changed the title [Messenger] chore: add exclude-receivers consume parameters [Messenger] Add --exclude-queues consume parameters Jun 30, 2025
@OskarStark OskarStark changed the title [Messenger] Add --exclude-queues consume parameters [Messenger] Add --exclude-queues consume parameters Jun 30, 2025
@jbdelhommeau jbdelhommeau force-pushed the messenger-exlude-receivers branch 3 times, most recently from 3ca4340 to 3379fda Compare June 30, 2025 13:09
@B-Galati
Copy link
Contributor

B-Galati commented Jul 1, 2025

@Kocal @jbdelhommeau Not sure about the naming of the option guys.

By default the command consumes from receivers/transports.

There is the option --queues but it's only for some implementations like AMQP.

So I guess we could have 2 options:

  • --exclude-queues
  • --exclude-receivers or --exclude-tranports (I prefer the later on my end because the config key name is transports)

Starting with the second option sounds more appropriate to me as it's not bound to some protocol/technologies. Also the current implementation is about receivers/transports not queues.

@jbdelhommeau jbdelhommeau force-pushed the messenger-exlude-receivers branch from 3379fda to dcde172 Compare July 1, 2025 12:51
@jbdelhommeau
Copy link
Contributor Author

I just push an new version more aligned with @B-Galati feedbacks.

@jbdelhommeau jbdelhommeau force-pushed the messenger-exlude-receivers branch from dcde172 to 4677777 Compare July 1, 2025 12:57
@@ -77,6 +77,7 @@ protected function configure(): void
new InputOption('queues', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Limit receivers to only consume from the specified queues'),
new InputOption('no-reset', null, InputOption::VALUE_NONE, 'Do not reset container services after each message'),
new InputOption('all', null, InputOption::VALUE_NONE, 'Consume messages from all receivers'),
new InputOption('exclude-transports', 'et', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Exclude specific receivers/transports from consumption (can only be used with --all)'),
Copy link
Member

Choose a reason for hiding this comment

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

Following previous conversation, the option --receivers describes which receivers/transports to consume, but here --exclude-transports describes which receivers/transports to not consume.

I feel like we should either have --receivers and --exclude-receivers, or --transports and --exclude-transports, but not both mixed.

I think the best option here is to go with --exclude-receivers (like your initial suggestion 😇).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants