Skip to content

[client] Rename config options. #547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2018
Merged
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
79 changes: 43 additions & 36 deletions pkg/enqueue/Client/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,59 +20,66 @@ class Config
/**
* @var string
*/
private $appName;
private $separator;

/**
* @var string
*/
private $routerTopicName;
private $app;

/**
* @var string
*/
private $routerQueueName;
private $routerTopic;

/**
* @var string
*/
private $defaultProcessorQueueName;
private $routerQueue;

/**
* @var string
*/
private $routerProcessorName;
private $defaultQueue;

/**
* @var string
*/
private $routerProcessor;

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

public function __construct(string $prefix, string $appName, string $routerTopicName, string $routerQueueName, string $defaultProcessorQueueName, string $routerProcessorName, array $transportConfig = [])
public function __construct(string $prefix, string $app, string $routerTopic, string $routerQueue, string $defaultQueue, string $routerProcessor, array $transportConfig = [])
{
$this->prefix = trim($prefix);
$this->appName = trim($appName);
$this->app = trim($app);

$this->routerTopicName = trim($routerTopicName);
if (empty($this->routerTopicName)) {
$this->routerTopic = trim($routerTopic);
if (empty($this->routerTopic)) {
throw new \InvalidArgumentException('Router topic is empty.');
}

$this->routerQueueName = trim($routerQueueName);
if (empty($this->routerQueueName)) {
$this->routerQueue = trim($routerQueue);
if (empty($this->routerQueue)) {
throw new \InvalidArgumentException('Router queue is empty.');
}

$this->defaultProcessorQueueName = trim($defaultProcessorQueueName);
if (empty($this->defaultProcessorQueueName)) {
$this->defaultQueue = trim($defaultQueue);
if (empty($this->defaultQueue)) {
throw new \InvalidArgumentException('Default processor queue name is empty.');
}

$this->routerProcessorName = trim($routerProcessorName);
if (empty($this->routerProcessorName)) {
$this->routerProcessor = trim($routerProcessor);
if (empty($this->routerProcessor)) {
throw new \InvalidArgumentException('Router processor name is empty.');
}

$this->transportConfig = $transportConfig;

$this->separator = '.';
}

public function getPrefix(): string
Expand All @@ -82,32 +89,32 @@ public function getPrefix(): string

public function getSeparator(): string
{
return '.';
return $this->separator;
}

public function getAppName(): string
public function getApp(): string
{
return $this->appName;
return $this->app;
}

public function getRouterTopicName(): string
public function getRouterTopic(): string
{
return $this->routerTopicName;
return $this->routerTopic;
}

public function getRouterQueueName(): string
public function getRouterQueue(): string
{
return $this->routerQueueName;
return $this->routerQueue;
}

public function getDefaultProcessorQueueName(): string
public function getDefaultQueue(): string
{
return $this->defaultProcessorQueueName;
return $this->defaultQueue;
}

public function getRouterProcessorName(): string
public function getRouterProcessor(): string
{
return $this->routerProcessorName;
return $this->routerProcessor;
}

/**
Expand All @@ -122,20 +129,20 @@ public function getTransportOption(string $name, $default = null)

public static function create(
string $prefix = null,
string $appName = null,
string $routerTopicName = null,
string $routerQueueName = null,
string $defaultProcessorQueueName = null,
string $routerProcessorName = null,
string $app = null,
string $routerTopic = null,
string $routerQueue = null,
string $defaultQueue = null,
string $routerProcessor = null,
array $transportConfig = []
): self {
return new static(
$prefix ?: '',
$appName ?: '',
$routerTopicName ?: 'router',
$routerQueueName ?: 'default',
$defaultProcessorQueueName ?: 'default',
$routerProcessorName ?: 'router',
$app ?: '',
$routerTopic ?: 'router',
$routerQueue ?: 'default',
$defaultQueue ?: 'default',
$routerProcessor ?: 'router',
$transportConfig
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ public function onPreReceived(Context $context)
}

$config = $this->driver->getConfig();
$queue = $this->driver->createQueue($config->getRouterQueueName());
$queue = $this->driver->createQueue($config->getRouterQueue());
if ($context->getInteropQueue()->getQueueName() != $queue->getQueueName()) {
return;
}

// RouterProcessor is our default message processor when that header is not set
$message->setProperty(Config::PROCESSOR, $config->getRouterProcessorName());
$message->setProperty(Config::PROCESSOR, $config->getRouterProcessor());

$context->getLogger()->debug(
'[SetRouterPropertiesExtension] '.
sprintf('Set router processor "%s"', $config->getRouterProcessorName())
sprintf('Set router processor "%s"', $config->getRouterProcessor())
);
}
}
4 changes: 2 additions & 2 deletions pkg/enqueue/Client/Driver/AmqpDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function setupBroker(LoggerInterface $logger = null): void
$log('Declare router exchange: %s', $routerTopic->getTopicName());
$this->getContext()->declareTopic($routerTopic);

$routerQueue = $this->createQueue($this->getConfig()->getRouterQueueName());
$routerQueue = $this->createQueue($this->getConfig()->getRouterQueue());
$log('Declare router queue: %s', $routerQueue->getQueueName());
$this->getContext()->declareQueue($routerQueue);

Expand Down Expand Up @@ -99,7 +99,7 @@ public function setupBroker(LoggerInterface $logger = null): void
protected function createRouterTopic(): Destination
{
$topic = $this->doCreateTopic(
$this->createTransportRouterTopicName($this->getConfig()->getRouterTopicName(), true)
$this->createTransportRouterTopicName($this->getConfig()->getRouterTopic(), true)
);
$topic->setType(AmqpTopic::TYPE_FANOUT);
$topic->addFlag(AmqpTopic::FLAG_DURABLE);
Expand Down
2 changes: 1 addition & 1 deletion pkg/enqueue/Client/Driver/FsDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function setupBroker(LoggerInterface $logger = null): void
};

// setup router
$routerQueue = $this->createQueue($this->getConfig()->getRouterQueueName());
$routerQueue = $this->createQueue($this->getConfig()->getRouterQueue());

$log('Declare router queue "%s" file: %s', $routerQueue->getQueueName(), $routerQueue->getFileInfo());
$this->getContext()->declareDestination($routerQueue);
Expand Down
10 changes: 5 additions & 5 deletions pkg/enqueue/Client/Driver/GenericDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public function sendToProcessor(Message $message): void
$message->setProperty(Config::PROCESSOR, $route->getProcessor());
$queue = $this->createRouteQueue($route);
} elseif ($topic && false == $message->getProperty(Config::PROCESSOR)) {
$message->setProperty(Config::PROCESSOR, $this->config->getRouterProcessorName());
$message->setProperty(Config::PROCESSOR, $this->config->getRouterProcessor());

$queue = $this->createQueue($this->config->getRouterQueueName());
$queue = $this->createQueue($this->config->getRouterQueue());
} elseif ($command) {
$route = $this->routeCollection->command($command);
if (false == $route) {
Expand Down Expand Up @@ -127,7 +127,7 @@ public function createQueue(string $clientQueueName, bool $prefix = true): Inter
public function createRouteQueue(Route $route): InteropQueue
{
$transportName = $this->createTransportQueueName(
$route->getQueue() ?: $this->config->getDefaultProcessorQueueName(),
$route->getQueue() ?: $this->config->getDefaultQueue(),
$route->isPrefixQueue()
);

Expand Down Expand Up @@ -225,7 +225,7 @@ protected function doSendToProcessor(InteropProducer $producer, InteropQueue $qu

protected function createRouterTopic(): Destination
{
return $this->createQueue($this->getConfig()->getRouterQueueName());
return $this->createQueue($this->getConfig()->getRouterQueue());
}

protected function createTransportRouterTopicName(string $name, bool $prefix): string
Expand All @@ -238,7 +238,7 @@ protected function createTransportRouterTopicName(string $name, bool $prefix): s
protected function createTransportQueueName(string $name, bool $prefix): string
{
$clientPrefix = $prefix ? $this->config->getPrefix() : '';
$clientAppName = $prefix ? $this->config->getAppName() : '';
$clientAppName = $prefix ? $this->config->getApp() : '';

return strtolower(implode($this->config->getSeparator(), array_filter([$clientPrefix, $clientAppName, $name])));
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/enqueue/Client/Driver/GpsDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function setupBroker(LoggerInterface $logger = null): void

// setup router
$routerTopic = $this->createRouterTopic();
$routerQueue = $this->createQueue($this->getConfig()->getRouterQueueName());
$routerQueue = $this->createQueue($this->getConfig()->getRouterQueue());

$log('Subscribe router topic to queue: %s -> %s', $routerTopic->getTopicName(), $routerQueue->getQueueName());
$this->getContext()->subscribe($routerTopic, $routerQueue);
Expand Down Expand Up @@ -58,7 +58,7 @@ public function setupBroker(LoggerInterface $logger = null): void
protected function createRouterTopic(): Destination
{
return $this->doCreateTopic(
$this->createTransportRouterTopicName($this->getConfig()->getRouterTopicName(), true)
$this->createTransportRouterTopicName($this->getConfig()->getRouterTopic(), true)
);
}
}
4 changes: 2 additions & 2 deletions pkg/enqueue/Client/Driver/RabbitMqStompDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ public function setupBroker(LoggerInterface $logger = null): void
}

// setup router
$routerExchange = $this->createTransportRouterTopicName($this->getConfig()->getRouterTopicName(), true);
$routerExchange = $this->createTransportRouterTopicName($this->getConfig()->getRouterTopic(), true);
$log('Declare router exchange: %s', $routerExchange);
$this->management->declareExchange($routerExchange, [
'type' => 'fanout',
'durable' => true,
'auto_delete' => false,
]);

$routerQueue = $this->createTransportQueueName($this->getConfig()->getRouterQueueName(), true);
$routerQueue = $this->createTransportQueueName($this->getConfig()->getRouterQueue(), true);
$log('Declare router queue: %s', $routerQueue);
$this->management->declareQueue($routerQueue, [
'auto_delete' => false,
Expand Down
4 changes: 2 additions & 2 deletions pkg/enqueue/Client/Driver/RdKafkaDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function setupBroker(LoggerInterface $logger = null): void
};

// setup router
$routerQueue = $this->createQueue($this->getConfig()->getRouterQueueName());
$routerQueue = $this->createQueue($this->getConfig()->getRouterQueue());
$log('Create router queue: %s', $routerQueue->getQueueName());
$this->getContext()->createConsumer($routerQueue);

Expand All @@ -51,7 +51,7 @@ public function setupBroker(LoggerInterface $logger = null): void
protected function createRouterTopic(): Destination
{
return $this->doCreateTopic(
$this->createTransportRouterTopicName($this->getConfig()->getRouterTopicName(), true)
$this->createTransportRouterTopicName($this->getConfig()->getRouterTopic(), true)
);
}
}
2 changes: 1 addition & 1 deletion pkg/enqueue/Client/Driver/SqsDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function setupBroker(LoggerInterface $logger = null): void
};

// setup router
$routerQueue = $this->createQueue($this->getConfig()->getRouterQueueName());
$routerQueue = $this->createQueue($this->getConfig()->getRouterQueue());
$log('Declare router queue: %s', $routerQueue->getQueueName());
$this->getContext()->declareQueue($routerQueue);

Expand Down
2 changes: 1 addition & 1 deletion pkg/enqueue/Client/Driver/StompDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function createRouterTopic(): Destination
{
/** @var StompDestination $topic */
$topic = $this->doCreateTopic(
$this->createTransportRouterTopicName($this->getConfig()->getRouterTopicName(), true)
$this->createTransportRouterTopicName($this->getConfig()->getRouterTopic(), true)
);
$topic->setDurable(true);
$topic->setAutoDelete(false);
Expand Down
4 changes: 2 additions & 2 deletions pkg/enqueue/Symfony/Client/ConsumeMessagesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int

$clientQueueNames = $input->getArgument('client-queue-names');
if (empty($clientQueueNames)) {
$clientQueueNames[$this->driver->getConfig()->getDefaultProcessorQueueName()] = true;
$clientQueueNames[$this->driver->getConfig()->getRouterQueueName()] = true;
$clientQueueNames[$this->driver->getConfig()->getDefaultQueue()] = true;
$clientQueueNames[$this->driver->getConfig()->getRouterQueue()] = true;

foreach ($this->driver->getRouteCollection()->all() as $route) {
if ($route->getQueue()) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/enqueue/Symfony/Client/RoutesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private function formatProcessor(Route $route): string

private function formatQueue(Route $route): string
{
$queue = $route->getQueue() ?: $this->config->getDefaultProcessorQueueName();
$queue = $route->getQueue() ?: $this->config->getDefaultQueue();

return $route->isPrefixQueue() ? $queue.' (prefixed)' : $queue.' (as is)';
}
Expand Down
Loading