Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Messenger] Prioritize receivers via transport configuration #57757

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.3
Choose a base branch
from

Conversation

petervanderwal
Copy link

@petervanderwal petervanderwal commented Jul 17, 2024

Q A
Branch? 7.2
Bug fix? no
New feature? yes
Deprecations? no
License MIT

As follow-up on #52411 (adding the --all option to messenger:consume) it would be good to be able to configure the receiver order via the transport configuration. That way, framework and bundle developers can pre-define/suggest the order in which messages should take precedence in the consumer**.

Configuring the priority has only effect when the consumer is executed with the --all option. When it is executed by manually passing the receiver names (e.g. messenger:consume two one), the argument order is respected.

**) I'm aware, with multiple bundles, this might not always fully result in the desired order of execution, but the same applies to (for example) event listeners. There are still options to overrule this.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.2 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "7.2" but it seems your PR description refers to branch "7.2 for features".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@petervanderwal petervanderwal force-pushed the prioritize-messenger-consumers-all branch from fcecc48 to 6059d84 Compare July 17, 2024 20:17
@@ -263,15 +265,23 @@ private function registerReceivers(ContainerBuilder $container, array $busIds):
$receiverMapping[$id] = new Reference($id);

foreach ($tags as $tag) {
$receiverPriority[$id] = max($tag['priority'] ?? 0, $receiverPriority[$id] ?? PHP_INT_MIN);
Copy link
Author

@petervanderwal petervanderwal Jul 17, 2024

Choose a reason for hiding this comment

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

Does it happen that a receiver service has multiple messenger.receiver tags? If that never happens then the "take the max priority of all added tags" logic can be simplified to a single easier to read $receiverPriority[$id] = $tag['priority'] ?? 0.

Based on the current FrameworkExtension code it looked like the answer would be "no, that never happens" but I didn't know whether there were other edge-cases.

Copy link
Member

Choose a reason for hiding this comment

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

why not using PriorityTaggedServiceTrait::findAndSortTaggedServices instead?

@alexislefebvre
Copy link
Contributor

I think the changelogs should explain (briefly) how to define bigger to lower priorities, do 0 has priority over 10?

@petervanderwal petervanderwal force-pushed the prioritize-messenger-consumers-all branch from 6059d84 to cbaae5d Compare July 25, 2024 18:07
@petervanderwal petervanderwal force-pushed the prioritize-messenger-consumers-all branch from cbaae5d to a1a9526 Compare July 25, 2024 18:10
@petervanderwal
Copy link
Author

I think the changelogs should explain (briefly) how to define bigger to lower priorities, do 0 has priority over 10?

Updated the changelog to indicate that the priority is passed on to the messenger.receiver service tag.

A higher priority (number) will go earlier than a lower priority -- https://symfony.com/doc/current/service_container/tags.html#tagged-services-with-priority

@@ -1612,6 +1612,7 @@ function ($a) {
->defaultNull()
->info('Rate limiter name to use when processing messages')
->end()
->integerNode('priority')->defaultValue(0)->info('Priority of this transport when the consumer is executed with the --all flag')->end()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
->integerNode('priority')->defaultValue(0)->info('Priority of this transport when the consumer is executed with the --all flag')->end()
->integerNode('priority')
->defaultValue(0)
->info('Priority of this transport when the consumer is executed with the --all flag')
->end()

@fabpot fabpot modified the milestones: 7.2, 7.3 Nov 20, 2024
@bendavies
Copy link
Contributor

this looks like a very worthwhile change.
currently using --all isn't really a viable option on highly prioritized transports.

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.

7 participants