Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,16 @@ protected function validateDuplicateNames(array $keys)
if (!isset($item['name'])) {
$item['name'] = '';
}
if (isset($names[$item['name']])) {
throw new InvalidConfigException("Duplicate name `{$item['name']}` in {$key}");

$name = $item['name'];
if(is_a($name, \UnitEnum::class)){
$name = $item['name']->name;
}
$names[$item['name']] = true;

if (isset($names[$name])) {
throw new InvalidConfigException("Duplicate name `{$name}` in {$key}");
}
$names[$name] = true;
}
}
}
Expand Down
20 changes: 16 additions & 4 deletions DependencyInjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ protected function registerProducers(Configuration $config)
{
$autoDeclare = $config->auto_declare;
foreach ($config->producers as $options) {
$serviceAlias = sprintf(Configuration::PRODUCER_SERVICE_NAME, $options['name']);

$name = $options['name'];
if(is_a($name, \UnitEnum::class)){
$name = $name->name;
}

$serviceAlias = sprintf(Configuration::PRODUCER_SERVICE_NAME, $name);
\Yii::$container->setSingleton($serviceAlias, function () use ($options, $autoDeclare) {
/**
* @var $connection AbstractConnection
Expand All @@ -98,7 +104,7 @@ protected function registerProducers(Configuration $config)
*/
$logger = \Yii::$container->get(Configuration::LOGGER_SERVICE_NAME);
$producer = new Producer($connection, $routing, $logger, $autoDeclare);
\Yii::$container->invoke([$producer, 'setName'], [$options['name']]);
\Yii::$container->invoke([$producer, 'setName'], [$name]);
\Yii::$container->invoke([$producer, 'setContentType'], [$options['content_type']]);
\Yii::$container->invoke([$producer, 'setDeliveryMode'], [$options['delivery_mode']]);
\Yii::$container->invoke([$producer, 'setSafe'], [$options['safe']]);
Expand All @@ -117,7 +123,13 @@ protected function registerConsumers(Configuration $config)
{
$autoDeclare = $config->auto_declare;
foreach ($config->consumers as $options) {
$serviceAlias = sprintf(Configuration::CONSUMER_SERVICE_NAME, $options['name']);

$name = $options['name'];
if(is_a($name, \UnitEnum::class)){
$name = $name->name;
}

$serviceAlias = sprintf(Configuration::CONSUMER_SERVICE_NAME, $name);
\Yii::$container->setSingleton($serviceAlias, function () use ($options, $autoDeclare) {
/**
* @var $connection AbstractConnection
Expand All @@ -137,7 +149,7 @@ protected function registerConsumers(Configuration $config)
$callbackClass = $this->getCallbackClass($callback);
$queues[$queueName] = [$callbackClass, 'execute'];
}
\Yii::$container->invoke([$consumer, 'setName'], [$options['name']]);
\Yii::$container->invoke([$consumer, 'setName'], [$name]);
\Yii::$container->invoke([$consumer, 'setQueues'], [$queues]);
\Yii::$container->invoke([$consumer, 'setQos'], [$options['qos']]);
\Yii::$container->invoke([$consumer, 'setIdleTimeout'], [$options['idle_timeout']]);
Expand Down