Skip to content

Instantly share code, notes, and snippets.

@JanMikes
Created September 7, 2017 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JanMikes/15e71c024b2557f8c9186ad37480ec44 to your computer and use it in GitHub Desktop.
Save JanMikes/15e71c024b2557f8c9186ad37480ec44 to your computer and use it in GitHub Desktop.
Multiple rabbit consumers in single command
<?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