Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #26864 [Messenger] Define multiple buses from the `framework.…
…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
- Loading branch information
Showing
25 changed files
with
518 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...undle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger_multiple_buses.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
$container->loadFromExtension('framework', array( | ||
'messenger' => array( | ||
'default_bus' => 'commands', | ||
'buses' => array( | ||
'commands' => null, | ||
'events' => array( | ||
'middlewares' => array( | ||
'tolerate_no_handler', | ||
), | ||
), | ||
'queries' => array( | ||
'default_middlewares' => false, | ||
'middlewares' => array( | ||
'route_messages', | ||
'tolerate_no_handler', | ||
'call_message_handler', | ||
), | ||
), | ||
), | ||
), | ||
)); |
11 changes: 0 additions & 11 deletions
11
.../FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger_validation_disabled.php
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
...e/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger_validation_enabled.php
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
...undle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger_multiple_buses.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:framework="http://symfony.com/schema/dic/symfony" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd | ||
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> | ||
|
||
<framework:config> | ||
<framework:messenger default-bus="commands"> | ||
<framework:bus name="commands" /> | ||
<framework:bus name="events"> | ||
<framework:middleware>tolerate_no_handler</framework:middleware> | ||
</framework:bus> | ||
<framework:bus name="queries" default-middlewares="false"> | ||
<framework:middleware>route_messages</framework:middleware> | ||
<framework:middleware>tolerate_no_handler</framework:middleware> | ||
<framework:middleware>call_message_handler</framework:middleware> | ||
</framework:bus> | ||
</framework:messenger> | ||
</framework:config> | ||
</container> |
15 changes: 0 additions & 15 deletions
15
.../FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger_validation_disabled.xml
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
...e/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger_validation_enabled.xml
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
...undle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger_multiple_buses.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
framework: | ||
messenger: | ||
default_bus: commands | ||
buses: | ||
commands: ~ | ||
events: | ||
middlewares: | ||
- "tolerate_no_handler" | ||
queries: | ||
default_middlewares: false | ||
middlewares: | ||
- "route_messages" | ||
- "tolerate_no_handler" | ||
- "call_message_handler" |
5 changes: 0 additions & 5 deletions
5
.../FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger_validation_disabled.yml
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
...e/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger_validation_enabled.yml
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.