You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bug #27084 [Messenger] Relax messenger config and fix some bugs (yceruto)
This PR was merged into the 4.1-dev branch.
Discussion
----------
[Messenger] Relax messenger config and fix some bugs
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
After playing a little with the config of this component I found some bugs around.
Reproducer:
1. Install a fresh Symfony flex project with `^4.0@dev` dependencies
2. Add the `symfony/messenger` requirement
3. Add the following configuration separately:
Note that `symfony/serializer` has not been installed yet. ATM it's not required.
----------------------
Configuring my custom transport (not amqp):
```yaml
framework:
messenger:
transports:
custom: 'my_transport://localhost/msgs'
routing:
'*': custom
```
**Before** (Current behaviour):
Threw a logic exception, IMO unrelated at this point:
> Using the default encoder/decoder, Symfony Messenger requires the Serializer. Enable it or install it by running "composer require symfony/serializer-pack".
**After** (Proposal):
Pass! The Messenger's serializer config is disabled by definition because the Serializer component is not installed yet, then the related (default) encoder/decoder aliases are invalid, so the amqp transport factory service is removed altogether.
----------------------
According to the previous exception I configured my custom encoder/decoder services:
```yaml
framework:
messenger:
encoder: App\Serializer\Serializer
decoder: App\Serializer\Serializer
transports:
custom: 'my_transport://localhost/msgs'
routing:
'*': custom
```
**Before**:
The same exception has been thrown, now a bit vague according to the config:
> Using the default encoder/decoder, Symfony Messenger requires the Serializer. Enable it or install it by running "composer require symfony/serializer-pack".
**After**:
Pass! the serializer is disabled by definition but there is custom encoder/decoder services, so let's keep the amqp transport factory with their custom encoder/decoder deps.
----------------------
Just enabling the serializer option:
```yaml
framework:
messenger:
serializer: true
```
**Before**:
Pass! Unexpected, as there is no transport configuration the exception wasn't thrown and still keeps the amqp transport factory service with invalid encoder/decoder (Serializer) dependencies.
**After**:
The Serializer config & support is verified if it's enabled regardless of the transport configuration and this exception is thrown for this case:
> The default Messenger serializer cannot be enabled as the Serializer support is not enabled.
I've removed the "install" part because at this point only we're checking whether the `framework.serializer` is enabled or not, so the next step after that should be enable the Serializer support in `framework.serializer`, which already verify whether the Serializer component is installed or not. IMO "composer require symfony/serializer-pack" should be there and not here. Also because `symfony/serializer` is not a hard dependency of this component.
----------------------
By last, I disabled the serializer option manually:
```yaml
framework:
messenger:
serializer: false
transports:
custom: 'my_transport://localhost/msgs'
routing:
'*': custom
```
**Before**:
I received this DI exception:
> The service "messenger.transport.amqp.factory" has a dependency on a non-existent service "messenger.transport.serializer".
**After**:
Pass! (same behaviour that the first example)
----------------------
As I explained earlier, this PR enables or disables the Messenger's serializer config based on the current Symfony platform and whether the Serializer component is installed or not, like other config with similar behaviour.
Tests included :)
Cheers!
Commits
-------
a05e2e2 Relax Messenger config and fix some bugs
Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+9-2
Original file line number
Diff line number
Diff line change
@@ -1444,15 +1444,18 @@ private function registerMessengerConfiguration(array $config, ContainerBuilder
1444
1444
$loader->load('messenger.xml');
1445
1445
1446
1446
if ($this->isConfigEnabled($container, $config['serializer'])) {
1447
-
if (\count($config['transports']) > 0 && !$this->isConfigEnabled($container, $serializerConfig)) {
1448
-
thrownewLogicException('Using the default encoder/decoder, Symfony Messenger requires the Serializer. Enable it or install it by running "composer require symfony/serializer-pack".');
1447
+
if (!$this->isConfigEnabled($container, $serializerConfig)) {
1448
+
thrownewLogicException('The default Messenger serializer cannot be enabled as the Serializer support is not available. Try enable it or install it by running "composer require symfony/serializer-pack".');
if (0 === strpos($transport['dsn'], 'amqp://') && !$container->hasDefinition('messenger.transport.amqp.factory')) {
1508
+
thrownewLogicException('The default AMQP transport is not available. Make sure you have installed and enabled the Serializer component. Try enable it or install it by running "composer require symfony/serializer-pack".');
* @expectedExceptionMessage Using the default encoder/decoder, Symfony Messenger requires the Serializer. Enable it or install it by running "composer require symfony/serializer-pack".
580
+
* @expectedExceptionMessage The default Messenger serializer cannot be enabled as the Serializer support is not available. Try enable it or install it by running "composer require symfony/serializer-pack".
* @expectedExceptionMessage The default AMQP transport is not available. Make sure you have installed and enabled the Serializer component. Try enable it or install it by running "composer require symfony/serializer-pack".
0 commit comments