Skip to content

Commit a37069d

Browse files
authored
Merge pull request #547 from php-enqueue/client-rename-some-options
[client] Rename config options.
2 parents 068f94d + eb61460 commit a37069d

15 files changed

+78
-71
lines changed

pkg/enqueue/Client/Config.php

+43-36
Original file line numberDiff line numberDiff line change
@@ -20,59 +20,66 @@ class Config
2020
/**
2121
* @var string
2222
*/
23-
private $appName;
23+
private $separator;
2424

2525
/**
2626
* @var string
2727
*/
28-
private $routerTopicName;
28+
private $app;
2929

3030
/**
3131
* @var string
3232
*/
33-
private $routerQueueName;
33+
private $routerTopic;
3434

3535
/**
3636
* @var string
3737
*/
38-
private $defaultProcessorQueueName;
38+
private $routerQueue;
3939

4040
/**
4141
* @var string
4242
*/
43-
private $routerProcessorName;
43+
private $defaultQueue;
44+
45+
/**
46+
* @var string
47+
*/
48+
private $routerProcessor;
4449

4550
/**
4651
* @var array
4752
*/
4853
private $transportConfig;
4954

50-
public function __construct(string $prefix, string $appName, string $routerTopicName, string $routerQueueName, string $defaultProcessorQueueName, string $routerProcessorName, array $transportConfig = [])
55+
public function __construct(string $prefix, string $app, string $routerTopic, string $routerQueue, string $defaultQueue, string $routerProcessor, array $transportConfig = [])
5156
{
5257
$this->prefix = trim($prefix);
53-
$this->appName = trim($appName);
58+
$this->app = trim($app);
5459

55-
$this->routerTopicName = trim($routerTopicName);
56-
if (empty($this->routerTopicName)) {
60+
$this->routerTopic = trim($routerTopic);
61+
if (empty($this->routerTopic)) {
5762
throw new \InvalidArgumentException('Router topic is empty.');
5863
}
5964

60-
$this->routerQueueName = trim($routerQueueName);
61-
if (empty($this->routerQueueName)) {
65+
$this->routerQueue = trim($routerQueue);
66+
if (empty($this->routerQueue)) {
6267
throw new \InvalidArgumentException('Router queue is empty.');
6368
}
6469

65-
$this->defaultProcessorQueueName = trim($defaultProcessorQueueName);
66-
if (empty($this->defaultProcessorQueueName)) {
70+
$this->defaultQueue = trim($defaultQueue);
71+
if (empty($this->defaultQueue)) {
6772
throw new \InvalidArgumentException('Default processor queue name is empty.');
6873
}
6974

70-
$this->routerProcessorName = trim($routerProcessorName);
71-
if (empty($this->routerProcessorName)) {
75+
$this->routerProcessor = trim($routerProcessor);
76+
if (empty($this->routerProcessor)) {
7277
throw new \InvalidArgumentException('Router processor name is empty.');
7378
}
7479

7580
$this->transportConfig = $transportConfig;
81+
82+
$this->separator = '.';
7683
}
7784

7885
public function getPrefix(): string
@@ -82,32 +89,32 @@ public function getPrefix(): string
8289

8390
public function getSeparator(): string
8491
{
85-
return '.';
92+
return $this->separator;
8693
}
8794

88-
public function getAppName(): string
95+
public function getApp(): string
8996
{
90-
return $this->appName;
97+
return $this->app;
9198
}
9299

93-
public function getRouterTopicName(): string
100+
public function getRouterTopic(): string
94101
{
95-
return $this->routerTopicName;
102+
return $this->routerTopic;
96103
}
97104

98-
public function getRouterQueueName(): string
105+
public function getRouterQueue(): string
99106
{
100-
return $this->routerQueueName;
107+
return $this->routerQueue;
101108
}
102109

103-
public function getDefaultProcessorQueueName(): string
110+
public function getDefaultQueue(): string
104111
{
105-
return $this->defaultProcessorQueueName;
112+
return $this->defaultQueue;
106113
}
107114

108-
public function getRouterProcessorName(): string
115+
public function getRouterProcessor(): string
109116
{
110-
return $this->routerProcessorName;
117+
return $this->routerProcessor;
111118
}
112119

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

123130
public static function create(
124131
string $prefix = null,
125-
string $appName = null,
126-
string $routerTopicName = null,
127-
string $routerQueueName = null,
128-
string $defaultProcessorQueueName = null,
129-
string $routerProcessorName = null,
132+
string $app = null,
133+
string $routerTopic = null,
134+
string $routerQueue = null,
135+
string $defaultQueue = null,
136+
string $routerProcessor = null,
130137
array $transportConfig = []
131138
): self {
132139
return new static(
133140
$prefix ?: '',
134-
$appName ?: '',
135-
$routerTopicName ?: 'router',
136-
$routerQueueName ?: 'default',
137-
$defaultProcessorQueueName ?: 'default',
138-
$routerProcessorName ?: 'router',
141+
$app ?: '',
142+
$routerTopic ?: 'router',
143+
$routerQueue ?: 'default',
144+
$defaultQueue ?: 'default',
145+
$routerProcessor ?: 'router',
139146
$transportConfig
140147
);
141148
}

pkg/enqueue/Client/ConsumptionExtension/SetRouterPropertiesExtension.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ public function onPreReceived(Context $context)
3333
}
3434

3535
$config = $this->driver->getConfig();
36-
$queue = $this->driver->createQueue($config->getRouterQueueName());
36+
$queue = $this->driver->createQueue($config->getRouterQueue());
3737
if ($context->getInteropQueue()->getQueueName() != $queue->getQueueName()) {
3838
return;
3939
}
4040

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

4444
$context->getLogger()->debug(
4545
'[SetRouterPropertiesExtension] '.
46-
sprintf('Set router processor "%s"', $config->getRouterProcessorName())
46+
sprintf('Set router processor "%s"', $config->getRouterProcessor())
4747
);
4848
}
4949
}

pkg/enqueue/Client/Driver/AmqpDriver.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function setupBroker(LoggerInterface $logger = null): void
7070
$log('Declare router exchange: %s', $routerTopic->getTopicName());
7171
$this->getContext()->declareTopic($routerTopic);
7272

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

@@ -99,7 +99,7 @@ public function setupBroker(LoggerInterface $logger = null): void
9999
protected function createRouterTopic(): Destination
100100
{
101101
$topic = $this->doCreateTopic(
102-
$this->createTransportRouterTopicName($this->getConfig()->getRouterTopicName(), true)
102+
$this->createTransportRouterTopicName($this->getConfig()->getRouterTopic(), true)
103103
);
104104
$topic->setType(AmqpTopic::TYPE_FANOUT);
105105
$topic->addFlag(AmqpTopic::FLAG_DURABLE);

pkg/enqueue/Client/Driver/FsDriver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function setupBroker(LoggerInterface $logger = null): void
2626
};
2727

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

3131
$log('Declare router queue "%s" file: %s', $routerQueue->getQueueName(), $routerQueue->getFileInfo());
3232
$this->getContext()->declareDestination($routerQueue);

pkg/enqueue/Client/Driver/GenericDriver.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ public function sendToProcessor(Message $message): void
7777
$message->setProperty(Config::PROCESSOR, $route->getProcessor());
7878
$queue = $this->createRouteQueue($route);
7979
} elseif ($topic && false == $message->getProperty(Config::PROCESSOR)) {
80-
$message->setProperty(Config::PROCESSOR, $this->config->getRouterProcessorName());
80+
$message->setProperty(Config::PROCESSOR, $this->config->getRouterProcessor());
8181

82-
$queue = $this->createQueue($this->config->getRouterQueueName());
82+
$queue = $this->createQueue($this->config->getRouterQueue());
8383
} elseif ($command) {
8484
$route = $this->routeCollection->command($command);
8585
if (false == $route) {
@@ -127,7 +127,7 @@ public function createQueue(string $clientQueueName, bool $prefix = true): Inter
127127
public function createRouteQueue(Route $route): InteropQueue
128128
{
129129
$transportName = $this->createTransportQueueName(
130-
$route->getQueue() ?: $this->config->getDefaultProcessorQueueName(),
130+
$route->getQueue() ?: $this->config->getDefaultQueue(),
131131
$route->isPrefixQueue()
132132
);
133133

@@ -225,7 +225,7 @@ protected function doSendToProcessor(InteropProducer $producer, InteropQueue $qu
225225

226226
protected function createRouterTopic(): Destination
227227
{
228-
return $this->createQueue($this->getConfig()->getRouterQueueName());
228+
return $this->createQueue($this->getConfig()->getRouterQueue());
229229
}
230230

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

243243
return strtolower(implode($this->config->getSeparator(), array_filter([$clientPrefix, $clientAppName, $name])));
244244
}

pkg/enqueue/Client/Driver/GpsDriver.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function setupBroker(LoggerInterface $logger = null): void
2929

3030
// setup router
3131
$routerTopic = $this->createRouterTopic();
32-
$routerQueue = $this->createQueue($this->getConfig()->getRouterQueueName());
32+
$routerQueue = $this->createQueue($this->getConfig()->getRouterQueue());
3333

3434
$log('Subscribe router topic to queue: %s -> %s', $routerTopic->getTopicName(), $routerQueue->getQueueName());
3535
$this->getContext()->subscribe($routerTopic, $routerQueue);
@@ -58,7 +58,7 @@ public function setupBroker(LoggerInterface $logger = null): void
5858
protected function createRouterTopic(): Destination
5959
{
6060
return $this->doCreateTopic(
61-
$this->createTransportRouterTopicName($this->getConfig()->getRouterTopicName(), true)
61+
$this->createTransportRouterTopicName($this->getConfig()->getRouterTopic(), true)
6262
);
6363
}
6464
}

pkg/enqueue/Client/Driver/RabbitMqStompDriver.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ public function setupBroker(LoggerInterface $logger = null): void
7676
}
7777

7878
// setup router
79-
$routerExchange = $this->createTransportRouterTopicName($this->getConfig()->getRouterTopicName(), true);
79+
$routerExchange = $this->createTransportRouterTopicName($this->getConfig()->getRouterTopic(), true);
8080
$log('Declare router exchange: %s', $routerExchange);
8181
$this->management->declareExchange($routerExchange, [
8282
'type' => 'fanout',
8383
'durable' => true,
8484
'auto_delete' => false,
8585
]);
8686

87-
$routerQueue = $this->createTransportQueueName($this->getConfig()->getRouterQueueName(), true);
87+
$routerQueue = $this->createTransportQueueName($this->getConfig()->getRouterQueue(), true);
8888
$log('Declare router queue: %s', $routerQueue);
8989
$this->management->declareQueue($routerQueue, [
9090
'auto_delete' => false,

pkg/enqueue/Client/Driver/RdKafkaDriver.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function setupBroker(LoggerInterface $logger = null): void
2727
};
2828

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

@@ -51,7 +51,7 @@ public function setupBroker(LoggerInterface $logger = null): void
5151
protected function createRouterTopic(): Destination
5252
{
5353
return $this->doCreateTopic(
54-
$this->createTransportRouterTopicName($this->getConfig()->getRouterTopicName(), true)
54+
$this->createTransportRouterTopicName($this->getConfig()->getRouterTopic(), true)
5555
);
5656
}
5757
}

pkg/enqueue/Client/Driver/SqsDriver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function setupBroker(LoggerInterface $logger = null): void
2626
};
2727

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

pkg/enqueue/Client/Driver/StompDriver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected function createRouterTopic(): Destination
6161
{
6262
/** @var StompDestination $topic */
6363
$topic = $this->doCreateTopic(
64-
$this->createTransportRouterTopicName($this->getConfig()->getRouterTopicName(), true)
64+
$this->createTransportRouterTopicName($this->getConfig()->getRouterTopic(), true)
6565
);
6666
$topic->setDurable(true);
6767
$topic->setAutoDelete(false);

pkg/enqueue/Symfony/Client/ConsumeMessagesCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
7474

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

8080
foreach ($this->driver->getRouteCollection()->all() as $route) {
8181
if ($route->getQueue()) {

pkg/enqueue/Symfony/Client/RoutesCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private function formatProcessor(Route $route): string
119119

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

124124
return $route->isPrefixQueue() ? $queue.' (prefixed)' : $queue.' (as is)';
125125
}

0 commit comments

Comments
 (0)