minor #35334 [FrameworkBundle] remove messenger cache if not enabled (dmaicher)

This PR was merged into the 4.3 branch.

Discussion
----------

[FrameworkBundle] remove messenger cache if not enabled

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes/no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -
<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/roadmap):
 - Always add tests and ensure they pass.
 - Never break backward compatibility (see https://symfony.com/bc).
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too.)
 - Features and deprecations must be submitted against branch master.
-->

I noticed on one of my apps that I have a cache pool related to the symfony messenger integration although I'm not using the messenger at all.

```
bin/console debug:container cache.messenger.restart_workers_signal

Information for Service "cache.messenger.restart_workers_signal"
================================================================

 An adapter that collects data about all cache calls.

 ---------------- --------------------------------------------------
  Option           Value
 ---------------- --------------------------------------------------
  Service ID       cache.messenger.restart_workers_signal
  Class            Symfony\Component\Cache\Adapter\TraceableAdapter
  Tags             cache.pool
                   kernel.reset (method: reset)
  Public           no
  Synthetic        no
  Lazy             no
  Shared           yes
  Abstract         no
  Autowired        no
  Autoconfigured   no
 ---------------- -----------------------------------------
```

So this PR removes the definition of the service in case the messenger integration is disabled.

Commits
-------

f81161df8d [FrameworkBundle] remove messenger cache if not enabled
This commit is contained in:
Nicolas Grekas 2020-01-14 17:22:33 +01:00
commit 6b95ea61a0
6 changed files with 34 additions and 0 deletions

View File

@ -292,6 +292,7 @@ class FrameworkExtension extends Extension
$container->removeDefinition('console.command.messenger_failed_messages_retry');
$container->removeDefinition('console.command.messenger_failed_messages_show');
$container->removeDefinition('console.command.messenger_failed_messages_remove');
$container->removeDefinition('cache.messenger.restart_workers_signal');
}
$propertyInfoEnabled = $this->isConfigEnabled($container, $config['property_info']);

View File

@ -414,6 +414,7 @@
<xsd:element name="bus" type="messenger_bus" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="default-bus" type="xsd:string" />
<xsd:attribute name="enabled" type="xsd:boolean" />
</xsd:complexType>
<xsd:complexType name="messenger_serializer">

View File

@ -0,0 +1,5 @@
<?php
$container->loadFromExtension('framework', [
'messenger' => false,
]);

View File

@ -0,0 +1,11 @@
<?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 https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
<framework:config>
<framework:messenger enabled="false" />
</framework:config>
</container>

View File

@ -0,0 +1,2 @@
framework:
messenger: false

View File

@ -659,9 +659,23 @@ abstract class FrameworkExtensionTest extends TestCase
$this->assertTrue($container->hasDefinition('web_link.add_link_header_listener'));
}
public function testMessengerServicesRemovedWhenDisabled()
{
$container = $this->createContainerFromFile('messenger_disabled');
$this->assertFalse($container->hasDefinition('console.command.messenger_consume_messages'));
$this->assertFalse($container->hasDefinition('console.command.messenger_debug'));
$this->assertFalse($container->hasDefinition('console.command.messenger_stop_workers'));
$this->assertFalse($container->hasDefinition('console.command.messenger_setup_transports'));
$this->assertFalse($container->hasDefinition('console.command.messenger_failed_messages_retry'));
$this->assertFalse($container->hasDefinition('console.command.messenger_failed_messages_show'));
$this->assertFalse($container->hasDefinition('console.command.messenger_failed_messages_remove'));
$this->assertFalse($container->hasDefinition('cache.messenger.restart_workers_signal'));
}
public function testMessenger()
{
$container = $this->createContainerFromFile('messenger');
$this->assertTrue($container->hasDefinition('console.command.messenger_consume_messages'));
$this->assertTrue($container->hasAlias('message_bus'));
$this->assertTrue($container->getAlias('message_bus')->isPublic());
$this->assertTrue($container->hasAlias('messenger.default_bus'));