Skip to content

Commit eff27bf

Browse files
committed
feature #46571 [Messenger] Add new messenger:count command that return a list of transports with their "to be processed" message count. (ktherage, ogizanagi, EXT - THERAGE Kevin)
This PR was squashed before being merged into the 6.2 branch. Discussion ---------- [Messenger] Add new `messenger:count` command that return a list of transports with their "to be processed" message count. | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | | License | MIT | Doc PR | Todo ### Why ? I worked on a project that didn't had insights on how many messages were present in "queues" (because of some hosting quirks) and to have this information we've developed a command that aims to make it possible via the Symfony's console. After a visio call with an ex-colleague on another Symfony project, it turns out that he was verry interested to have this command in Symfony. I've also discused with @Jean-Beru that literraly pushed me too open that PR. So here I am. ### What does it does ? This quite simple, like for the `setup-transport` command it takes in input all configured transports' receivers and **Only if they implement `Symfony\Component\Messenger\Transport\Receiver\MessageCountAwareInterface`** it gets the message count and prints it out in a pretty little table. ### Limitation This command won't work if the configured transport's receiver does not implement `Symfony\Component\Messenger\Transport\Receiver\MessageCountAwareInterface` ### A small demo ? https://user-images.githubusercontent.com/35264408/171853603-6807f0d1-a251-4180-b34b-80d3a3c49b92.mp4 Commits ------- e5433cd6da [Messenger] Add new `messenger:count` command that return a list of transports with their "to be processed" message count.
2 parents 8ee4406 + 5ce0833 commit eff27bf

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
use Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpTransportFactory;
110110
use Symfony\Component\Messenger\Bridge\Beanstalkd\Transport\BeanstalkdTransportFactory;
111111
use Symfony\Component\Messenger\Bridge\Redis\Transport\RedisTransportFactory;
112+
use Symfony\Component\Messenger\Command\StatsCommand;
112113
use Symfony\Component\Messenger\Handler\BatchHandlerInterface;
113114
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
114115
use Symfony\Component\Messenger\MessageBus;
@@ -510,6 +511,7 @@ public function load(array $configs, ContainerBuilder $container)
510511
$this->registerMessengerConfiguration($config['messenger'], $container, $loader, $config['validation']);
511512
} else {
512513
$container->removeDefinition('console.command.messenger_consume_messages');
514+
$container->removeDefinition('console.command.messenger_stats');
513515
$container->removeDefinition('console.command.messenger_debug');
514516
$container->removeDefinition('console.command.messenger_stop_workers');
515517
$container->removeDefinition('console.command.messenger_setup_transports');
@@ -1977,6 +1979,10 @@ private function registerMessengerConfiguration(array $config, ContainerBuilder
19771979
throw new LogicException('Messenger support cannot be enabled as the Messenger component is not installed. Try running "composer require symfony/messenger".');
19781980
}
19791981

1982+
if (!class_exists(StatsCommand::class)) {
1983+
$container->removeDefinition('console.command.messenger_stats');
1984+
}
1985+
19801986
$loader->load('messenger.php');
19811987

19821988
if (!interface_exists(DenormalizerInterface::class)) {

Resources/config/console.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use Symfony\Component\Console\EventListener\ErrorListener;
4343
use Symfony\Component\Dotenv\Command\DebugCommand as DotenvDebugCommand;
4444
use Symfony\Component\Messenger\Command\ConsumeMessagesCommand;
45+
use Symfony\Component\Messenger\Command\StatsCommand;
4546
use Symfony\Component\Messenger\Command\DebugCommand;
4647
use Symfony\Component\Messenger\Command\FailedMessagesRemoveCommand;
4748
use Symfony\Component\Messenger\Command\FailedMessagesRetryCommand;
@@ -206,6 +207,13 @@
206207
])
207208
->tag('console.command')
208209

210+
->set('console.command.messenger_stats', StatsCommand::class)
211+
->args([
212+
service('messenger.receiver_locator'),
213+
abstract_arg('Receivers names'),
214+
])
215+
->tag('console.command')
216+
209217
->set('console.command.router_debug', RouterDebugCommand::class)
210218
->args([
211219
service('router'),
@@ -334,5 +342,5 @@
334342
service('secrets.local_vault')->ignoreOnInvalid(),
335343
])
336344
->tag('console.command')
337-
;
345+
;
338346
};

0 commit comments

Comments
 (0)