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

Skip to content

[Messenger] AMQP configurable routing key & multiple queues #30770

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

Closed

Conversation

weaverryan
Copy link
Member

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? TODO
Fixed tickets #29950
License MIT
Doc PR symfony/symfony-docs#11236

Hi!

This builds on top of #30008. In fact, I would be perfectly happy if @G15N pulled in my commit into his branch and finished it on his PR (we would close this one then). I just wanted to make sure the 2nd half got done.

This adds 2 things:

  1. A new AmqpRoutingKeyStamp that allows you to configure the routing key
  2. The ability to define multiple queues on an AMQP transport, each bound to 0 or more routing keys.

It also fixes a few things I'm pretty sure were wrong - specifically the attributes and flags configuration for a queue were also sent when publishing a message. I don't think that makes sense: when you're publishing a message, you have no idea what queue you will go to. These 2 options are now NOT configurable for each message, which makes me wonder if we should add 2 new stamps for these, or merge onto one bigger AmqpConfigurationStamp class.

Cheers!

Guillaume Gammelin and others added 2 commits March 28, 2019 14:15
…ents' into amqp-multiple-queues-routing-keys

* G15N/ticket-29950-bus-dispatch-enhancements:
  [messenger] Adds a stamp to provide a routing key on message publishing.
$this->queue()->bind($this->exchange()->getName(), $this->queueConfiguration['routing_key'] ?? null);
foreach ($this->queuesConfiguration as $queueName => $queueConfig) {
$this->queue($queueName)->declareQueue();
foreach ($queueConfig['routing_keys'] ?? [] as $routingKey) {
Copy link

@bentcoder bentcoder Mar 29, 2019

Choose a reason for hiding this comment

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

@weaverryan Just to confirm, as far as I understand, this line addresses the first point (AMQP configuration) I made here. Am I correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

I’m not sure exactly which was your first point. But this part allows you to declare that you want messenger to create multiple queues on your behalf and create multiple binds for each queue. I’m pretty sure this was at least one of your issues :). This part is all about creating and binding of queues - these specific lines say nothing about the publishing process or what routing keys are used.

$this->queue()->bind($this->exchange()->getName(), $this->queueConfiguration['routing_key'] ?? null);
foreach ($this->queuesConfiguration as $queueName => $queueConfig) {
$this->queue($queueName)->declareQueue();
foreach ($queueConfig['routing_keys'] ?? [] as $routingKey) {
Copy link

Choose a reason for hiding this comment

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

@weaverryan , don't forget to rename routing_keys to binding_keys for this binding part (also in constructor doc)

@bentcoder
Copy link

@weaverryan My comment above referes to section below:


e.g.

framework:
    messenger:
        transports:
            amqp:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
                options:
                    ...
                    queue:
                        ...
                        routing_keys: ['key_1', 'key_2' ...]

@weaverryan
Copy link
Member Author

@bentcoder yep, then that code is indeed doing what you want. It allows you to bind multiple routing keys to the queue, though we may rename them to binding_keys, I think that’s more accurate.

@weaverryan
Copy link
Member Author

Happily closing in favor of @G15N continuing the work on #30008

@weaverryan weaverryan closed this Mar 31, 2019
@weaverryan weaverryan deleted the amqp-multiple-queues-routing-keys branch March 31, 2019 16:00
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.3 Apr 30, 2019
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.

5 participants