Commit 1298fa6a authored by Maxime Veber's avatar Maxime Veber
Browse files

feat: add swarrot to the story

parent ffe834a3
......@@ -13,12 +13,21 @@ Test
docker-compose up -d
bin/console app:gen-messages 1400
bin/console messenger:consume --limit=1400
bin/console swarrot:consume:simple --limit 1400
```
Résultat
--------
Résultat Symfony 5.2
--------------------
Le test précédent tourne environ en 10 secondes sur mon ordinateur.
Par défaut messenger consume un message en 7ms environ sur ma machine.
On peut atteindre 140 messages par seconde sur ma machine.
Résultat Symfony 5.3
--------------------
Le test précédent tourne environ en 3 secondes sur mon ordinateur. Les performances sont comparables à swarrot.
......@@ -7,13 +7,14 @@
"php": ">=8.0.0",
"ext-ctype": "*",
"ext-iconv": "*",
"symfony/console": "5.2.*",
"symfony/dotenv": "5.2.*",
"swarrot/swarrot": "^4.11",
"symfony/console": "5.3.*",
"symfony/dotenv": "5.3.*",
"symfony/flex": "^1.3.1",
"symfony/framework-bundle": "5.2.*",
"symfony/framework-bundle": "5.3.*",
"symfony/maker-bundle": "^1.31",
"symfony/messenger": "5.2.*",
"symfony/yaml": "5.2.*"
"symfony/messenger": "5.3.*",
"symfony/yaml": "5.3.*"
},
"config": {
"optimize-autoloader": true,
......@@ -55,7 +56,7 @@
"extra": {
"symfony": {
"allow-contrib": false,
"require": "5.2.*"
"require": "5.3.*"
}
}
}
This diff is collapsed.
version: "3.9"
services:
rabbitmq:
image: rabbitmq:3-management
ports:
- 5672:5672
- 8080:15672
<?php
namespace App\Command;
use Psr\Log\NullLogger;
use Swarrot\Broker\Message;
use Swarrot\Broker\MessageProvider\PeclPackageMessageProvider;
use Swarrot\Consumer;
use Swarrot\Processor\ProcessorInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class SwarrotConsumeSimpleCommand extends Command
{
public const QUEUE_NAME = 'messages';
protected static $defaultName = 'swarrot:consume:simple';
protected static $defaultDescription = 'Consume swarrot simple message';
protected function configure(): void
{
$this
->setDescription(self::$defaultDescription)
->addOption('limit', null, InputOption::VALUE_OPTIONAL, 'Maximum message to manage', 1000)
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
// Create connection
$connection = new \AMQPConnection();
$connection->connect();
$channel = new \AMQPChannel($connection);
// Get the queue to consume
$queue = new \AMQPQueue($channel);
$queue->setName(self::QUEUE_NAME);
$messageProvider = new PeclPackageMessageProvider($queue);
$processor = new class implements ProcessorInterface {
public function process(Message $message, array $options): bool
{
//echo sprintf("Consume message #%d\n", $message->getId());
return true;
}
};
$stack = (new \Swarrot\Processor\Stack\Builder())
->push('Swarrot\Processor\MaxMessages\MaxMessagesProcessor', new NullLogger())
->push('Swarrot\Processor\ExceptionCatcher\ExceptionCatcherProcessor')
->push('Swarrot\Processor\Ack\AckProcessor', $messageProvider)
;
$processor = $stack->resolve($processor);
$consumer = new Consumer($messageProvider, $processor);
$consumer->consume(['max_messages' => (int) $input->getOption('limit')]);
return Command::SUCCESS;
}
}
......@@ -17,6 +17,9 @@
"psr/log": {
"version": "1.1.4"
},
"swarrot/swarrot": {
"version": "v4.11.0"
},
"symfony/amqp-messenger": {
"version": "v5.2.7"
},
......@@ -130,6 +133,9 @@
"config/packages/messenger.yaml"
]
},
"symfony/options-resolver": {
"version": "v5.2.4"
},
"symfony/polyfill-intl-grapheme": {
"version": "v1.22.1"
},
......@@ -145,6 +151,9 @@
"symfony/polyfill-php80": {
"version": "v1.22.1"
},
"symfony/polyfill-php81": {
"version": "v1.23.0"
},
"symfony/redis-messenger": {
"version": "v5.2.7"
},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment