Skip to content

Commit 6b95ea6

Browse files
minor symfony#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 ------- f81161d [FrameworkBundle] remove messenger cache if not enabled
2 parents ec0333c + f81161d commit 6b95ea6

File tree

6 files changed

+34
-0
lines changed

6 files changed

+34
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ public function load(array $configs, ContainerBuilder $container)
292292
$container->removeDefinition('console.command.messenger_failed_messages_retry');
293293
$container->removeDefinition('console.command.messenger_failed_messages_show');
294294
$container->removeDefinition('console.command.messenger_failed_messages_remove');
295+
$container->removeDefinition('cache.messenger.restart_workers_signal');
295296
}
296297

297298
$propertyInfoEnabled = $this->isConfigEnabled($container, $config['property_info']);

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@
414414
<xsd:element name="bus" type="messenger_bus" minOccurs="0" maxOccurs="unbounded" />
415415
</xsd:sequence>
416416
<xsd:attribute name="default-bus" type="xsd:string" />
417+
<xsd:attribute name="enabled" type="xsd:boolean" />
417418
</xsd:complexType>
418419

419420
<xsd:complexType name="messenger_serializer">
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'messenger' => false,
5+
]);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config>
9+
<framework:messenger enabled="false" />
10+
</framework:config>
11+
</container>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
framework:
2+
messenger: false

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,23 @@ public function testWebLink()
659659
$this->assertTrue($container->hasDefinition('web_link.add_link_header_listener'));
660660
}
661661

662+
public function testMessengerServicesRemovedWhenDisabled()
663+
{
664+
$container = $this->createContainerFromFile('messenger_disabled');
665+
$this->assertFalse($container->hasDefinition('console.command.messenger_consume_messages'));
666+
$this->assertFalse($container->hasDefinition('console.command.messenger_debug'));
667+
$this->assertFalse($container->hasDefinition('console.command.messenger_stop_workers'));
668+
$this->assertFalse($container->hasDefinition('console.command.messenger_setup_transports'));
669+
$this->assertFalse($container->hasDefinition('console.command.messenger_failed_messages_retry'));
670+
$this->assertFalse($container->hasDefinition('console.command.messenger_failed_messages_show'));
671+
$this->assertFalse($container->hasDefinition('console.command.messenger_failed_messages_remove'));
672+
$this->assertFalse($container->hasDefinition('cache.messenger.restart_workers_signal'));
673+
}
674+
662675
public function testMessenger()
663676
{
664677
$container = $this->createContainerFromFile('messenger');
678+
$this->assertTrue($container->hasDefinition('console.command.messenger_consume_messages'));
665679
$this->assertTrue($container->hasAlias('message_bus'));
666680
$this->assertTrue($container->getAlias('message_bus')->isPublic());
667681
$this->assertTrue($container->hasAlias('messenger.default_bus'));

0 commit comments

Comments
 (0)