retrieve rabbitmq configuration from configuration.yml

This commit is contained in:
aynsix
2019-09-20 16:03:54 +04:00
parent 7541885637
commit c712cb7cc3

View File

@@ -32,11 +32,12 @@ class WorkerConfigurationServiceProvider implements ServiceProviderInterface
$app['alchemy_queues.queues'] = $app->share(function (Application $app) { $app['alchemy_queues.queues'] = $app->share(function (Application $app) {
$defaultConfiguration = [ $defaultConfiguration = [
'worker-queue' => [ 'worker-queue' => [
'registry' => 'alchemy_worker.queue_registry', 'registry' => 'alchemy_worker.queue_registry',
'host' => 'localhost', 'host' => 'localhost',
'port' => 5672, 'port' => 5672,
'user' => 'guest', 'user' => 'guest',
'vhost' => '/' 'password' => 'guest',
'vhost' => '/'
] ]
]; ];
@@ -46,19 +47,22 @@ class WorkerConfigurationServiceProvider implements ServiceProviderInterface
$queueConfigurations = $configuration->get(['workers', 'queue'], $defaultConfiguration); $queueConfigurations = $configuration->get(['workers', 'queue'], $defaultConfiguration);
$queueConfiguration = reset($queueConfigurations); $config = [];
$queueKey = key($queueConfigurations);
if (! isset($queueConfiguration['name'])) { foreach($queueConfigurations as $name => $queueConfiguration) {
if (! is_string($queueKey)) { $queueKey = $name;
throw new \RuntimeException('Invalid queue configuration: configuration has no key or name.');
if (! isset($queueConfiguration['name'])) {
if (! is_string($queueKey)) {
throw new \RuntimeException('Invalid queue configuration: configuration has no key or name.');
}
$queueConfiguration['name'] = $queueKey;
} }
$queueConfiguration['name'] = $queueKey; $config[$queueConfiguration['name']] = $queueConfiguration ;
} }
$config = [ $queueConfiguration['name'] => $queueConfiguration ];
return $config; return $config;
} }
catch (RuntimeException $exception) { catch (RuntimeException $exception) {