-
Notifications
You must be signed in to change notification settings - Fork 59
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
Default middleware stack #100
Comments
To be honest, I don't know. |
@odolbeau I don't mean to contribute a default middleware stack. I want to give you the possibility to define your middleware stack once, and reuse it as a basis (meaning you could add to it). The configuration could look like this : Solution 1 "default" or "base" middleware stackswarrot:
default_middleware_stack:
- configurator: swarrot.process.ack
- configurator: another.processor
- configurator: you.get.the.idea
consumers:
no_additional_processor_consumer:
processor: innermost_processor
consumer_with_extra_processor_at_the_top_of_the_stack:
processor: innermost_processor
middleware_stack:
- configurator: additional_configurator
consumer_with_extra_processor_at_the_bottom_of_the_stack:
processor: innermost_processor
middleware_stack:
- configurator: additional_configurator
- configurator: swarrot.process.ack
- configurator: another.processor
- configurator: you.get.the.idea Another potential improvement would be to allow the definition of several middleware stacks, and merge them Solution 2 : reference any number of middleware stacks and merge them togetherswarrot:
middleware_stacks:
arbitrary_name:
- configurator: swarrot.process.ack
- configurator: another.processor
- configurator: you.get.the.idea
whatever:
- configurator: additional_configurator
consumers:
no_additional_processor_consumer:
processor: innermost_processor
middleware_stack:
- arbitrary_name
consumer_with_extra_processor_at_the_top_of_the_stack:
processor: innermost_processor
middleware_stack:
- arbitrary_name
- whatever
my_third_consumer:
processor: innermost_processor
middleware_stack: # size of the stack: 5
- arbitrary_name
- whatever
- configurator: extra_configurator # BC-compatibility is
# achieved by looking at the contents of the array : if it is a
# simple string, it is a reference to a middleware_stack, if
# it is a hash, then the definition is inline |
In this case, I don't really understand what you want to do. |
@odolbeau I'm doing very different jobs, based on the same kind of message => I need several queues consumers, it's the best practice if we believe this article : https://derickbailey.com/2015/09/02/rabbitmq-best-practices-for-designing-exchanges-queues-and-bindings/ .
Likewise, trying to route the message to a specific service once it is in the consumer seems like an anti-pattern to me. I also plan to add to a new consumer, that will consume a very different kind of message. In that case, I will also need a separate consumer, but in all cases, I will use the |
I have a slight preference for the first solution, the second one might be overkill, and is more verbose, although more flexible. What do you think? |
To clarify, yes, but the innermost processor (the one I write) is not necessarily the same. I say not necessarily because I also happen to have two consumer with exactly the same stack, but a different vhost : there is a "real vhost", from where legit events come (produced by a legacy django app), that I have read-only access on, and a "local vhost", that produces similar events, so that I can do a bulk import by producing many events if I need to (from my non-legacy symfony app). |
If I understand well, you would like to have a new configuration key like Did I understand well? |
Yes, that's the first solution I described.
You could complement it on a consumer-per-consumer basis, but you wouldn't be able to override it. So if there is an item you want for 90% of your consumers, you can't add it to the default stack (which would maybe better be named as
It would be useful only if you have n consumer with the exact same base stack :
Here, the
It may or may not be augmented with other processors. Also, for me, after reading your docs, especially the config part, I think the innermost job |
Solution 3: chain configuratorswarrot:
chain_configurator:
default: # can be any string, if not empty, a service instance of
# ChainConfigurator will be created (swarrot.processor.chain.default)
- configurator: swarrot.process.ack
extras:
requeue_on_error: false
- configurator: another.processor
- configurator: you.get.the.idea
consumers:
no_additional_processor_consumer:
processor: innermost_processor
middleware_stack:
- configurator: swarrot.processor.chain.default
consumer_with_extra_processor_at_the_top_of_the_stack:
processor: innermost_processor
middleware_stack:
- configurator: swarrot.processor.chain.default
- configurator: additional_configurator
consumer_with_extra_processor_at_the_bottom_of_the_stack:
processor: innermost_processor
middleware_stack:
- configurator: additional_configurator
- configurator: swarrot.processor.chain.default |
As discussed with @greg0ire, the latest solution looks like the best one. Furthermore, compared to other solutions, the middleware stack definition stay unchanged, there is only a new part in the config to declare chain configurators. |
@odolbeau any update on this feature ? |
@olaurendeau what do you think? |
Stumbled upon this issue since I wanted to "beauty" my yaml. This really needs to happen, config file with many consumers looks rather dirty. |
@duraki would you like to contribute it? |
I think it would be handy to be able to define a default middleware stack that would server as a basis for every consumer. I discovered the
swarrot.processor.ack
and I can't imagine why one would ever not use it. I can provide a PR for that.The text was updated successfully, but these errors were encountered: