Skip to content

Commit c030a33

Browse files
authored
Merge pull request #545 from php-enqueue/remove-config-parameters
Remove config parameters
2 parents 79f4217 + 263fda7 commit c030a33

28 files changed

+179
-278
lines changed

pkg/enqueue-bundle/DependencyInjection/Configuration.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Enqueue\Bundle\DependencyInjection;
44

5-
use Enqueue\Client\Config;
65
use Enqueue\Client\RouterProcessor;
76
use Enqueue\Symfony\DependencyInjection\TransportFactory;
87
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
@@ -35,10 +34,10 @@ public function getConfigTreeBuilder(): TreeBuilder
3534
->booleanNode('traceable_producer')->defaultValue($this->debug)->end()
3635
->scalarNode('prefix')->defaultValue('enqueue')->end()
3736
->scalarNode('app_name')->defaultValue('app')->end()
38-
->scalarNode('router_topic')->defaultValue(Config::DEFAULT_PROCESSOR_QUEUE_NAME)->cannotBeEmpty()->end()
39-
->scalarNode('router_queue')->defaultValue(Config::DEFAULT_PROCESSOR_QUEUE_NAME)->cannotBeEmpty()->end()
37+
->scalarNode('router_topic')->defaultValue('default')->cannotBeEmpty()->end()
38+
->scalarNode('router_queue')->defaultValue('default')->cannotBeEmpty()->end()
4039
->scalarNode('router_processor')->defaultValue(RouterProcessor::class)->end()
41-
->scalarNode('default_processor_queue')->defaultValue(Config::DEFAULT_PROCESSOR_QUEUE_NAME)->cannotBeEmpty()->end()
40+
->scalarNode('default_processor_queue')->defaultValue('default')->cannotBeEmpty()->end()
4241
->integerNode('redelivered_delay_time')->min(0)->defaultValue(0)->end()
4342
->end()->end()
4443
->arrayNode('consumption')->addDefaultsIfNotSet()->children()

pkg/enqueue-bundle/Tests/Functional/Client/ProducerTest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public function testShouldSendMessageInstanceAsCommandWithoutNeedForReply()
7272
$this->assertCount(1, $traces);
7373
$this->assertEquals('theMessage', $traces[0]['body']);
7474
$this->assertEquals([
75-
'enqueue.processor_name' => 'test_command_subscriber_processor',
76-
'enqueue.command_name' => 'theCommand',
75+
'enqueue.processor' => 'test_command_subscriber_processor',
76+
'enqueue.command' => 'theCommand',
7777
], $traces[0]['properties']);
7878
}
7979

@@ -93,8 +93,8 @@ public function testShouldSendExclusiveCommandWithNeedForReply()
9393
$this->assertCount(1, $traces);
9494
$this->assertEquals('theMessage', $traces[0]['body']);
9595
$this->assertEquals([
96-
'enqueue.processor_name' => 'theExclusiveCommandName',
97-
'enqueue.command_name' => 'theExclusiveCommandName',
96+
'enqueue.processor' => 'theExclusiveCommandName',
97+
'enqueue.command' => 'theExclusiveCommandName',
9898
], $traces[0]['properties']);
9999
}
100100

@@ -114,8 +114,8 @@ public function testShouldSendMessageInstanceCommandWithNeedForReply()
114114
$this->assertCount(1, $traces);
115115
$this->assertEquals('theMessage', $traces[0]['body']);
116116
$this->assertEquals([
117-
'enqueue.processor_name' => 'test_command_subscriber_processor',
118-
'enqueue.command_name' => 'theCommand',
117+
'enqueue.processor' => 'test_command_subscriber_processor',
118+
'enqueue.command' => 'theCommand',
119119
], $traces[0]['properties']);
120120
}
121121

pkg/enqueue/Client/Config.php

+7-31
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,13 @@
44

55
class Config
66
{
7-
const PARAMETER_TOPIC_NAME = 'enqueue.topic_name';
8-
const PARAMETER_COMMAND_NAME = 'enqueue.command_name';
9-
const PARAMETER_PROCESSOR_NAME = 'enqueue.processor_name';
10-
11-
/**
12-
* @deprecated
13-
*/
14-
const PARAMETER_PROCESSOR_QUEUE_NAME = 'enqueue.processor_queue_name';
15-
16-
const DEFAULT_PROCESSOR_QUEUE_NAME = 'default';
17-
18-
/**
19-
* @deprecated
20-
*/
21-
const COMMAND_TOPIC = '__command__';
7+
const TOPIC = 'enqueue.topic';
8+
const COMMAND = 'enqueue.command';
9+
const PROCESSOR = 'enqueue.processor';
10+
const EXPIRE = 'enqueue.expire';
11+
const PRIORITY = 'enqueue.priority';
12+
const DELAY = 'enqueue.delay';
13+
const CONTENT_TYPE = 'enqueue.content_type';
2214

2315
/**
2416
* @var string
@@ -118,22 +110,6 @@ public function getRouterProcessorName(): string
118110
return $this->routerProcessorName;
119111
}
120112

121-
/**
122-
* @deprecated
123-
*/
124-
public function createTransportRouterTopicName(string $name): string
125-
{
126-
return strtolower(implode('.', array_filter([trim($this->prefix), trim($name)])));
127-
}
128-
129-
/**
130-
* @deprecated
131-
*/
132-
public function createTransportQueueName(string $name): string
133-
{
134-
return strtolower(implode('.', array_filter([trim($this->prefix), trim($this->appName), trim($name)])));
135-
}
136-
137113
/**
138114
* @deprecated
139115
*

pkg/enqueue/Client/ConsumptionExtension/ExclusiveCommandExtension.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ public function onPreReceived(Context $context)
3333
$message = $context->getInteropMessage();
3434
$queue = $context->getInteropQueue();
3535

36-
if ($message->getProperty(Config::PARAMETER_TOPIC_NAME)) {
36+
if ($message->getProperty(Config::TOPIC)) {
3737
return;
3838
}
39-
if ($message->getProperty(Config::PARAMETER_COMMAND_NAME)) {
39+
if ($message->getProperty(Config::COMMAND)) {
4040
return;
4141
}
42-
if ($message->getProperty(Config::PARAMETER_PROCESSOR_NAME)) {
42+
if ($message->getProperty(Config::PROCESSOR)) {
4343
return;
4444
}
4545

@@ -51,8 +51,8 @@ public function onPreReceived(Context $context)
5151
$context->getLogger()->debug('[ExclusiveCommandExtension] This is a exclusive command queue and client\'s properties are not set. Setting them');
5252

5353
$route = $this->queueToRouteMap[$queue->getQueueName()];
54-
$message->setProperty(Config::PARAMETER_PROCESSOR_NAME, $route->getProcessor());
55-
$message->setProperty(Config::PARAMETER_COMMAND_NAME, $route->getSource());
54+
$message->setProperty(Config::PROCESSOR, $route->getProcessor());
55+
$message->setProperty(Config::COMMAND, $route->getSource());
5656
}
5757
}
5858

pkg/enqueue/Client/ConsumptionExtension/SetRouterPropertiesExtension.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(DriverInterface $driver)
2828
public function onPreReceived(Context $context)
2929
{
3030
$message = $context->getInteropMessage();
31-
if ($message->getProperty(Config::PARAMETER_PROCESSOR_NAME)) {
31+
if ($message->getProperty(Config::PROCESSOR)) {
3232
return;
3333
}
3434

@@ -39,7 +39,7 @@ public function onPreReceived(Context $context)
3939
}
4040

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

4444
$context->getLogger()->debug(
4545
'[SetRouterPropertiesExtension] '.

pkg/enqueue/Client/DelegateProcessor.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ public function __construct(ProcessorRegistryInterface $registry)
2626
*/
2727
public function process(InteropMessage $message, Context $context)
2828
{
29-
$processorName = $message->getProperty(Config::PARAMETER_PROCESSOR_NAME);
29+
$processorName = $message->getProperty(Config::PROCESSOR);
3030
if (false == $processorName) {
3131
throw new \LogicException(sprintf(
3232
'Got message without required parameter: "%s"',
33-
Config::PARAMETER_PROCESSOR_NAME
33+
Config::PROCESSOR
3434
));
3535
}
3636

pkg/enqueue/Client/Driver/GenericDriver.php

+20-20
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ public function __construct(
4747

4848
public function sendToRouter(Message $message): void
4949
{
50-
if ($message->getProperty(Config::PARAMETER_COMMAND_NAME)) {
50+
if ($message->getProperty(Config::COMMAND)) {
5151
throw new \LogicException('Command must not be send to router but go directly to its processor.');
5252
}
53-
if (false == $message->getProperty(Config::PARAMETER_TOPIC_NAME)) {
53+
if (false == $message->getProperty(Config::TOPIC)) {
5454
throw new \LogicException('Topic name parameter is required but is not set');
5555
}
5656

@@ -63,21 +63,21 @@ public function sendToRouter(Message $message): void
6363

6464
public function sendToProcessor(Message $message): void
6565
{
66-
$topic = $message->getProperty(Config::PARAMETER_TOPIC_NAME);
67-
$command = $message->getProperty(Config::PARAMETER_COMMAND_NAME);
66+
$topic = $message->getProperty(Config::TOPIC);
67+
$command = $message->getProperty(Config::COMMAND);
6868

6969
/** @var InteropQueue $queue */
7070
$queue = null;
71-
if ($topic && $processor = $message->getProperty(Config::PARAMETER_PROCESSOR_NAME)) {
71+
if ($topic && $processor = $message->getProperty(Config::PROCESSOR)) {
7272
$route = $this->routeCollection->topicAndProcessor($topic, $processor);
7373
if (false == $route) {
7474
throw new \LogicException(sprintf('There is no route for topic "%s" and processor "%s"', $topic, $processor));
7575
}
7676

77-
$message->setProperty(Config::PARAMETER_PROCESSOR_NAME, $route->getProcessor());
77+
$message->setProperty(Config::PROCESSOR, $route->getProcessor());
7878
$queue = $this->createRouteQueue($route);
79-
} elseif ($topic && false == $message->getProperty(Config::PARAMETER_PROCESSOR_NAME)) {
80-
$message->setProperty(Config::PARAMETER_PROCESSOR_NAME, $this->config->getRouterProcessorName());
79+
} elseif ($topic && false == $message->getProperty(Config::PROCESSOR)) {
80+
$message->setProperty(Config::PROCESSOR, $this->config->getRouterProcessorName());
8181

8282
$queue = $this->createQueue($this->config->getRouterQueueName());
8383
} elseif ($command) {
@@ -86,7 +86,7 @@ public function sendToProcessor(Message $message): void
8686
throw new \LogicException(sprintf('There is no route for command "%s".', $command));
8787
}
8888

89-
$message->setProperty(Config::PARAMETER_PROCESSOR_NAME, $route->getProcessor());
89+
$message->setProperty(Config::PROCESSOR, $route->getProcessor());
9090
$queue = $this->createRouteQueue($route);
9191
} else {
9292
throw new \LogicException('Either topic or command parameter must be set.');
@@ -96,15 +96,15 @@ public function sendToProcessor(Message $message): void
9696

9797
$producer = $this->context->createProducer();
9898

99-
if (null !== $delay = $transportMessage->getProperty('X-Enqueue-Delay')) {
99+
if (null !== $delay = $transportMessage->getProperty(Config::DELAY)) {
100100
$producer->setDeliveryDelay($delay * 1000);
101101
}
102102

103-
if (null !== $expire = $transportMessage->getProperty('X-Enqueue-Expire')) {
103+
if (null !== $expire = $transportMessage->getProperty(Config::EXPIRE)) {
104104
$producer->setTimeToLive($expire * 1000);
105105
}
106106

107-
if (null !== $priority = $transportMessage->getProperty('X-Enqueue-Priority')) {
107+
if (null !== $priority = $transportMessage->getProperty(Config::PRIORITY)) {
108108
$priorityMap = $this->getPriorityMap();
109109

110110
$producer->setPriority($priorityMap[$priority]);
@@ -149,19 +149,19 @@ public function createTransportMessage(Message $clientMessage): InteropMessage
149149
$transportMessage->setCorrelationId($clientMessage->getCorrelationId());
150150

151151
if ($contentType = $clientMessage->getContentType()) {
152-
$transportMessage->setProperty('X-Enqueue-Content-Type', $contentType);
152+
$transportMessage->setProperty(Config::CONTENT_TYPE, $contentType);
153153
}
154154

155155
if ($priority = $clientMessage->getPriority()) {
156-
$transportMessage->setProperty('X-Enqueue-Priority', $priority);
156+
$transportMessage->setProperty(Config::PRIORITY, $priority);
157157
}
158158

159159
if ($expire = $clientMessage->getExpire()) {
160-
$transportMessage->setProperty('X-Enqueue-Expire', $expire);
160+
$transportMessage->setProperty(Config::EXPIRE, $expire);
161161
}
162162

163163
if ($delay = $clientMessage->getDelay()) {
164-
$transportMessage->setProperty('X-Enqueue-Delay', $delay);
164+
$transportMessage->setProperty(Config::DELAY, $delay);
165165
}
166166

167167
return $transportMessage;
@@ -179,19 +179,19 @@ public function createClientMessage(InteropMessage $transportMessage): Message
179179
$clientMessage->setReplyTo($transportMessage->getReplyTo());
180180
$clientMessage->setCorrelationId($transportMessage->getCorrelationId());
181181

182-
if ($contentType = $transportMessage->getProperty('X-Enqueue-Content-Type')) {
182+
if ($contentType = $transportMessage->getProperty(Config::CONTENT_TYPE)) {
183183
$clientMessage->setContentType($contentType);
184184
}
185185

186-
if ($priority = $transportMessage->getProperty('X-Enqueue-Priority')) {
186+
if ($priority = $transportMessage->getProperty(Config::PRIORITY)) {
187187
$clientMessage->setPriority($priority);
188188
}
189189

190-
if ($delay = $transportMessage->getProperty('X-Enqueue-Delay')) {
190+
if ($delay = $transportMessage->getProperty(Config::DELAY)) {
191191
$clientMessage->setDelay((int) $delay);
192192
}
193193

194-
if ($expire = $transportMessage->getProperty('X-Enqueue-Expire')) {
194+
if ($expire = $transportMessage->getProperty(Config::EXPIRE)) {
195195
$clientMessage->setExpire((int) $expire);
196196
}
197197

pkg/enqueue/Client/Driver/RabbitMqStompDriver.php

+3-3
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->getConfig()->createTransportRouterTopicName($this->getConfig()->getRouterTopicName());
79+
$routerExchange = $this->createTransportRouterTopicName($this->getConfig()->getRouterTopicName(), 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->getConfig()->createTransportQueueName($this->getConfig()->getRouterQueueName());
87+
$routerQueue = $this->createTransportQueueName($this->getConfig()->getRouterQueueName(), true);
8888
$log('Declare router queue: %s', $routerQueue);
8989
$this->management->declareQueue($routerQueue, [
9090
'auto_delete' => false,
@@ -169,7 +169,7 @@ protected function doSendToRouter(InteropProducer $producer, Destination $topic,
169169
*/
170170
protected function doSendToProcessor(InteropProducer $producer, InteropQueue $destination, InteropMessage $transportMessage): void
171171
{
172-
if ($delay = $transportMessage->getProperty('X-Enqueue-Delay')) {
172+
if ($delay = $transportMessage->getProperty(Config::DELAY)) {
173173
$producer->setDeliveryDelay(null);
174174
$destination = $this->createDelayedTopic($destination);
175175
}

pkg/enqueue/Client/DriverPreSend.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ public function getDriver(): DriverInterface
3434

3535
public function isEvent(): bool
3636
{
37-
return (bool) $this->message->getProperty(Config::PARAMETER_TOPIC_NAME);
37+
return (bool) $this->message->getProperty(Config::TOPIC);
3838
}
3939

4040
public function isCommand(): bool
4141
{
42-
return (bool) $this->message->getProperty(Config::PARAMETER_COMMAND_NAME);
42+
return (bool) $this->message->getProperty(Config::COMMAND);
4343
}
4444

4545
public function getCommand(): string
4646
{
47-
return $this->message->getProperty(Config::PARAMETER_COMMAND_NAME);
47+
return $this->message->getProperty(Config::COMMAND);
4848
}
4949

5050
public function getTopic(): string
5151
{
52-
return $this->message->getProperty(Config::PARAMETER_TOPIC_NAME);
52+
return $this->message->getProperty(Config::TOPIC);
5353
}
5454
}

pkg/enqueue/Client/PostSend.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ public function getDriver(): DriverInterface
3434

3535
public function isEvent(): bool
3636
{
37-
return (bool) $this->message->getProperty(Config::PARAMETER_TOPIC_NAME);
37+
return (bool) $this->message->getProperty(Config::TOPIC);
3838
}
3939

4040
public function isCommand(): bool
4141
{
42-
return (bool) $this->message->getProperty(Config::PARAMETER_COMMAND_NAME);
42+
return (bool) $this->message->getProperty(Config::COMMAND);
4343
}
4444

4545
public function getCommand(): string
4646
{
47-
return $this->message->getProperty(Config::PARAMETER_COMMAND_NAME);
47+
return $this->message->getProperty(Config::COMMAND);
4848
}
4949

5050
public function getTopic(): string
5151
{
52-
return $this->message->getProperty(Config::PARAMETER_TOPIC_NAME);
52+
return $this->message->getProperty(Config::TOPIC);
5353
}
5454
}

pkg/enqueue/Client/Producer.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function sendEvent(string $topic, $message): void
4848
$this->extension->onPreSendEvent($preSend);
4949

5050
$message = $preSend->getMessage();
51-
$message->setProperty(Config::PARAMETER_TOPIC_NAME, $preSend->getTopic());
51+
$message->setProperty(Config::TOPIC, $preSend->getTopic());
5252

5353
$this->doSend($message);
5454
}
@@ -79,7 +79,7 @@ public function sendCommand(string $command, $message, bool $needReply = false):
7979
}
8080
}
8181

82-
$message->setProperty(Config::PARAMETER_COMMAND_NAME, $command);
82+
$message->setProperty(Config::COMMAND, $command);
8383
$message->setScope(Message::SCOPE_APP);
8484

8585
$this->doSend($message);
@@ -103,8 +103,8 @@ private function doSend(Message $message): void
103103
));
104104
}
105105

106-
if ($message->getProperty(Config::PARAMETER_PROCESSOR_NAME)) {
107-
throw new \LogicException(sprintf('The %s property must not be set.', Config::PARAMETER_PROCESSOR_NAME));
106+
if ($message->getProperty(Config::PROCESSOR)) {
107+
throw new \LogicException(sprintf('The %s property must not be set.', Config::PROCESSOR));
108108
}
109109

110110
if (!$message->getMessageId()) {

0 commit comments

Comments
 (0)