-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Messenger] Allow different types of busses #26652
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
Comments
The Whole Event bus with recorder taken from Simple bus package PR is still on sroze's fork of symfony |
I think here there are two topics here.
|
Hello, |
As a first step, I suggest we allow to define multiple buses like that: framework:
messenger:
buses:
default: ~
command: ~
query: ~
We would have the "calling handler" and "routing the sender" middlewares tagged without a given bus so they would be shared across all the buses. |
@sroze: This is not enough. edit: It seems that I missed the 2nd part of your post, where you say, that the tag will have the bus attribute. |
That seems to be a robust start 👍 Later, what about adding middleware in the YAML configuration, instead of using tags? framework:
messenger:
buses:
all:
middlewares:
- "Symfony\\Messenger\\HandlerMiddleware"
default: ~
command:
middlewares:
- "App\\MyMiddleware" Another option would be a to use a Doctrine-bundle style configuration, though I find it more ambiguous (are middlewares on the top overriden? Then we should re-add them?...). framework:
messenger:
middlewares: # Will apply to all, Doctrine-bundle configuration style
- "Symfony\\Messenger\\HandlerMiddleware"
buses:
default: ~
command:
middlewares:
- "Symfony\\Messenger\\HandlerMiddleware"
- "App\\MyMiddleware" |
I like the idea of a default bus (one that can be autowired) and knows about all configured handlers, with a "zero or more handlers" requirement. |
Pull-request is here: #26864 🚀 |
…messenger.buses` configuration (sroze) This PR was squashed before being merged into the 4.1-dev branch (closes #26864). Discussion ---------- [Messenger] Define multiple buses from the `framework.messenger.buses` configuration | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #26652 | License | MIT | Doc PR | symfony/symfony-docs#9617 Not everybody will benefit from having only one bus, especially with the CQRS-like usages. While keeping the extremely use of use of the single bus, this PR has the following: - Create multiple buses from the YAML configuration - Tag middleware only a specific buses - Register middlewares from the YAML configuration Even if it's visible in the PR's tests, here's how it will look like, for a completely full-customised version: ```yaml framework: messenger: default_bus: commands buses: commands: ~ events: middlewares: - validation - route_messages - "Your\\Middleware\\Service" - call_message_handler ``` A few things to note: 1. The YAML configuration creates `messenger.bus.[name]` services for the buses. 2. The YAML configuration for middleware just adds tags to the corresponding middlewares. 3. If the middleware definition does not exists, it creates it. (without any magic on the arguments though, if it isn't auto-wirable, well... "your problem") 4. In the PR, there is this "TolerateNoHandler" middleware that is a great example for event buses Commits ------- e5deb84 [Messenger] Define multiple buses from the `framework.messenger.buses` configuration
I want to have multiple buses with different features. Example of different buses might be:
Default bus
Command bus
Event bus
Query bus
Example config:
The text was updated successfully, but these errors were encountered: