Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Messenger] support for multiple bindings on the same queue#37722

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

inferont
Copy link

@inferontinferont commentedJul 31, 2020
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
TicketsFix#37233
LicenseMIT

Description
When using header based queues and exchanges to keep track of events, one may want to have multiple bindings on those headers in those queues. Adding a few lines of code to Connection.php in amqp-messenger will allow Symfony Messenger to support this type of queue. This is pretty standard in other amqp library implementations.

Details
This PR introduces a small refactoring that deprecates the binding_keys and binding_arguments options with a new array option, bindings. This bindings options allows any number of arrays with a 'key' string value, another 'arguments' array value, and possibly an 'exchange' value in future revisions to support multiple exchanges.

Example

async_consume_task:    dsn: '%env(MESSENGER_TRANSPORT_DSN)%'    options:        vhost: message-bus        exchange:            name: message-bus-exchange            type: headers        queues:            'cart-purchases-header-queue':                'bindings':                    'manual-messages':                        'arguments':                            message-type: 'task'                            subject: 'cart'                            x-bind: all                    'customer-messages':                        'arguments':                            message-type: 'event'                            subject: 'customer'                            x-bind: all            'general-events-topic-queue':                'bindings':                    0:                        'key': 'entity-change.*.*.*'

githoober reacted with thumbs up emoji
@inferontinferont requested a review fromsroze as acode ownerJuly 31, 2020 21:25
@nicolas-grekasnicolas-grekas changed the title37233 multiple bindings[Messenger] support for multiple bindings on the same queueAug 1, 2020
@nicolas-grekasnicolas-grekas added this to thenext milestoneAug 1, 2020
@nicolas-grekas
Copy link
Member

nicolas-grekas commentedAug 1, 2020
edited
Loading

Thanks for the PR.

For future PRs of yours, please note that we prefer proper description + title on PRs, because that's what is recorded in the changelog and in the git history. Referring to "the linked issue" misses all these benefits. Could you please update the description in such a way that documenting the PR becomes "trivial", as in "almost a copy/paste of the PR's description"?

Could you please add some tests also?

@inferont
Copy link
Author

@nicolas-grekas Thanks for your response.

Please see the added unit tests and the updated description. I am not sure I handled deprecation correctly here so feel free to offer any other suggestions.

Copy link
Member

@weaverryanweaverryan left a comment

Choose a reason for hiding this comment

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

On a high level, this makes sense. If we allow multiple bindings, then it makes sense for each binding to be able to have its own binding arguments.

foreach ($queueConfig['bindings'] ?? [] as $binding) {
$this->queue($queueName)->bind($this->exchangeOptions['name'], $binding['key'] ?? null, $binding['arguments'] ?? []);
}
if (isset($queueConfig['bindings']) && empty($queueConfig['binding_keys'])) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this isn't needed? Because if$queueConfig['binding_keys']) is empty, then the next foreach wouldn't do anything anyways.

Copy link
Author

Choose a reason for hiding this comment

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

The '?? [null]' in the next line will ensure that bind is called at least once with a null $bindingKey if 'binding_keys' is empty. This would have the effect of binding all messages from the exchange to the queue.

@@ -231,6 +241,8 @@ private static function validateOptions(array $options): void

if (0 < \count($invalidQueueOptions = array_diff(array_keys($queue), self::AVAILABLE_QUEUE_OPTIONS))) {
trigger_deprecation('symfony/messenger', '5.1', 'Invalid queue option(s) "%s" passed to the AMQP Messenger transport. Passing invalid queue options is deprecated.', implode('", "', $invalidQueueOptions));
} elseif (0 < \count($invalidQueueOptions = array_diff(array_keys($queue), self::AVAILABLE_QUEUE_OPTIONS_52))) {
trigger_deprecation('symfony/messenger', '5.2', 'Deprecated queue option(s) "%s" passed to the AMQP Messenger transport. The "bindings" option should be used rather than "binding_keys" and "binding_arguments".', implode('", "', $invalidQueueOptions));
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this is quite right. In 5.1, we ADDED validation of the options in general. In 5.2, you're deprecatingbindings. So basically, if you passbindings, we should say thatbindings is deprecated in 5.2. If we pass any other invalid option, it would use the existing deprecation message.

Also, could we add validation thatbindings only containskey andarguments keys?

Copy link
Author

Choose a reason for hiding this comment

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

I fixed this and added validation on each individual binding. Thanks!

@@ -443,6 +455,12 @@ private function setupExchangeAndQueues(): void

foreach ($this->queuesOptions as $queueName => $queueConfig) {
$this->queue($queueName)->declareQueue();
foreach ($queueConfig['bindings'] ?? [] as $binding) {
Copy link
Member

Choose a reason for hiding this comment

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

In the example in the PR description, you show using an array key underbindings - likemanual-messages, but that is not used here. What is the purpose of this YAML key? You also show an example without one. Which is the correct usage?

Copy link
Author

@inferontinferontOct 1, 2020
edited
Loading

Choose a reason for hiding this comment

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

I am not sure there is or should be a correct usage. The original intent was that these bindings could have a developer/human friendly name. I have found that using these names for the bindings is useful when we have more than a dozen bindings. In my projects, all of these bindings would ideally have a name. I do not think I would want to force another developer to do this generally though. I'm okay with any suggestions here though.

@fabpot
Copy link
Member

@weaverryan Can you have another look?

@fabpotfabpot closed thisOct 7, 2020
@fabpot
Copy link
Member

We've just moved away frommaster as the main branch to use5.x instead. Unfortunately, I cannot reopen the PR and change the target branch to5.x. Can you open a new PR referencing this one to not loose the discussion? Thank you for your understanding and for your help.

@inferont
Copy link
Author

@fabpot Sure, here you go:#38485

@nicolas-grekasnicolas-grekas modified the milestones:5.x,5.2Oct 14, 2020
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@srozesrozeAwaiting requested review from sroze

@weaverryanweaverryanAwaiting requested review from weaverryan

Assignees
No one assigned
Projects
None yet
Milestone
5.4
Development

Successfully merging this pull request may close these issues.

[Messenger] amqp-messenger does not allow a queue to have more than one binding
5 participants
@inferont@nicolas-grekas@fabpot@weaverryan@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp