Skip to content

Commit

Permalink
Merge pull request #28 from rtyshyk/feature-rpc-server-support
Browse files Browse the repository at this point in the history
feature (configuration import): add support for rpc-server
#27
  • Loading branch information
Phobetor authored May 21, 2018
2 parents 3162e47 + 0bbdb43 commit 5ad2ef2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ protected function addCommands(ArrayNodeDefinition $node)
->children()
->scalarNode('rabbitmq_consumer')->defaultValue('rabbitmq:consumer')->end()
->scalarNode('rabbitmq_multiple_consumer')->defaultValue('rabbitmq:multiple-consumer')->end()
->scalarNode('rabbitmq_rpc_server')->defaultValue('rabbitmq:rpc-server')->end()
->end()
->end()
->end()
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/RabbitMqSupervisorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function load(array $configs, ContainerBuilder $container)

public function prepend(ContainerBuilder $container)
{
$attributeNames = array('consumers', 'multiple_consumers');
$attributeNames = array('consumers', 'multiple_consumers', 'rpc_servers');
$attributes = array_combine($attributeNames, array_fill(0, count($attributeNames), []));

foreach ($container->getExtensions() as $name => $extension) {
Expand Down
1 change: 1 addition & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
- "%phobetor_rabbitmq_supervisor.commands%"
- "%phobetor_rabbitmq_supervisor.consumers%"
- "%phobetor_rabbitmq_supervisor.multiple_consumers%"
- "%phobetor_rabbitmq_supervisor.rpc_servers%"
- "%phobetor_rabbitmq_supervisor.config%"
- "%kernel.environment%"

Expand Down
32 changes: 24 additions & 8 deletions Services/RabbitMqSupervisor.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class RabbitMqSupervisor
*/
private $config;

/**
* @var array
*/
private $rpcServers;

/**
* @var string
*/
Expand All @@ -52,16 +57,18 @@ class RabbitMqSupervisor
* @param array $commands
* @param array $consumers
* @param array $multipleConsumers
* @param array $rpcServers
* @param array $config
* @param string $environment
*/
public function __construct(Supervisor $supervisor, array $paths, array $commands, $consumers, $multipleConsumers, $config, $environment)
public function __construct(Supervisor $supervisor, EngineInterface $templating, array $paths, array $commands, $consumers, $multipleConsumers, $rpcServers, $config)
{
$this->supervisor = $supervisor;
$this->paths = $paths;
$this->commands = $commands;
$this->consumers = $consumers;
$this->multipleConsumers = $multipleConsumers;
$this->rpcServers = $rpcServers;
$this->config = $config;
$this->environment = $environment;
}
Expand Down Expand Up @@ -112,6 +119,9 @@ public function build()
// generate program configuration files for all multiple consumers
$this->generateWorkerConfigurations(array_keys($this->multipleConsumers), $this->commands['rabbitmq_multiple_consumer']);

//generate program configuration files for all rpc_server consumers
$this->generateWorkerConfigurations(array_keys($this->rpcServers), $this->commands['rabbitmq_rpc_server']);

// start supervisor and reload configuration
$this->start();
$this->supervisor->reloadAndUpdate();
Expand Down Expand Up @@ -300,17 +310,23 @@ private function generateWorkerConfigurations($names, $baseCommand)
if (!empty($messages)) {
$flags['messages'] = sprintf('--messages=%d', $messages);
}
$memoryLimit = $this->getConsumerOption($name, 'memory-limit');
if (!empty($memoryLimit)) {
$flags['memory-limit'] = sprintf('--memory-limit=%d', $memoryLimit);
}

$debug = $this->getConsumerOption($name, 'debug');
if (!empty($debug)) {
$flags['debug'] = '--debug';
}
$withoutSignals = $this->getConsumerOption($name, 'without-signals');
if (!empty($withoutSignals)) {
$flags['without-signals'] = '--without-signals';

//rabbitmq:rpc-server does not support options below
if ($baseCommand !== 'rabbitmq:rpc-server') {
$memoryLimit = $this->getConsumerOption($name, 'memory-limit');
if (!empty($memoryLimit)) {
$flags['memory-limit'] = sprintf('--memory-limit=%d', $memoryLimit);
}

$withoutSignals = $this->getConsumerOption($name, 'without-signals');
if (!empty($withoutSignals)) {
$flags['without-signals'] = '--without-signals';
}
}

$command = sprintf('%s %s %s', $commandName, $name, implode(' ', $flags));
Expand Down

0 comments on commit 5ad2ef2

Please sign in to comment.