Created
September 7, 2017 00:31
-
-
Save JanMikes/15e71c024b2557f8c9186ad37480ec44 to your computer and use it in GitHub Desktop.
Multiple rabbit consumers in single command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(ticks=1, strict_types=1); | |
require_once __DIR__ . '/../vendor/autoload.php'; | |
use Arara\Process\Action\Command; | |
use Arara\Process\Child; | |
use Arara\Process\Control; | |
use Kdyby\RabbitMq\DI\RabbitMqExtension; | |
use Nette\DI\Container; | |
/** @var Child[] $children */ | |
$children = []; | |
$control = new Control(); | |
/** @var Container $container */ | |
$container = require __DIR__ . '/../app/bootstrap.php'; | |
$services = $container->findByTag(RabbitMqExtension::TAG_CONSUMER); | |
foreach ($services as $consumerName => $enabled) { | |
$consumerName = str_replace('rabbitmq.consumer.', '', $consumerName); | |
$command = new Command("bin/console rabbitmq:consumer $consumerName -v"); | |
$child = new Child($command, $control); | |
$children[] = $child; | |
$child->start(); | |
} | |
for (;;) { | |
foreach ($children as $child) { | |
if (!$child->isRunning()) { | |
echo 'Child not running, terminating the process!' . PHP_EOL; | |
$control->flush(5); | |
exit(1); | |
} | |
} | |
sleep(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment