Skip to content

Remove config parameters #545

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 5 commits 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
7 changes: 3 additions & 4 deletions pkg/enqueue-bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Enqueue\Bundle\DependencyInjection;

use Enqueue\Client\Config;
use Enqueue\Client\RouterProcessor;
use Enqueue\Symfony\DependencyInjection\TransportFactory;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
Expand Down Expand Up @@ -35,10 +34,10 @@ public function getConfigTreeBuilder(): TreeBuilder
->booleanNode('traceable_producer')->defaultValue($this->debug)->end()
->scalarNode('prefix')->defaultValue('enqueue')->end()
->scalarNode('app_name')->defaultValue('app')->end()
->scalarNode('router_topic')->defaultValue(Config::DEFAULT_PROCESSOR_QUEUE_NAME)->cannotBeEmpty()->end()
->scalarNode('router_queue')->defaultValue(Config::DEFAULT_PROCESSOR_QUEUE_NAME)->cannotBeEmpty()->end()
->scalarNode('router_topic')->defaultValue('default')->cannotBeEmpty()->end()
->scalarNode('router_queue')->defaultValue('default')->cannotBeEmpty()->end()
->scalarNode('router_processor')->defaultValue(RouterProcessor::class)->end()
->scalarNode('default_processor_queue')->defaultValue(Config::DEFAULT_PROCESSOR_QUEUE_NAME)->cannotBeEmpty()->end()
->scalarNode('default_processor_queue')->defaultValue('default')->cannotBeEmpty()->end()
->integerNode('redelivered_delay_time')->min(0)->defaultValue(0)->end()
->end()->end()
->arrayNode('consumption')->addDefaultsIfNotSet()->children()
Expand Down
12 changes: 6 additions & 6 deletions pkg/enqueue-bundle/Tests/Functional/Client/ProducerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public function testShouldSendMessageInstanceAsCommandWithoutNeedForReply()
$this->assertCount(1, $traces);
$this->assertEquals('theMessage', $traces[0]['body']);
$this->assertEquals([
'enqueue.processor_name' => 'test_command_subscriber_processor',
'enqueue.command_name' => 'theCommand',
'enqueue.processor' => 'test_command_subscriber_processor',
'enqueue.command' => 'theCommand',
], $traces[0]['properties']);
}

Expand All @@ -93,8 +93,8 @@ public function testShouldSendExclusiveCommandWithNeedForReply()
$this->assertCount(1, $traces);
$this->assertEquals('theMessage', $traces[0]['body']);
$this->assertEquals([
'enqueue.processor_name' => 'theExclusiveCommandName',
'enqueue.command_name' => 'theExclusiveCommandName',
'enqueue.processor' => 'theExclusiveCommandName',
'enqueue.command' => 'theExclusiveCommandName',
], $traces[0]['properties']);
}

Expand All @@ -114,8 +114,8 @@ public function testShouldSendMessageInstanceCommandWithNeedForReply()
$this->assertCount(1, $traces);
$this->assertEquals('theMessage', $traces[0]['body']);
$this->assertEquals([
'enqueue.processor_name' => 'test_command_subscriber_processor',
'enqueue.command_name' => 'theCommand',
'enqueue.processor' => 'test_command_subscriber_processor',
'enqueue.command' => 'theCommand',
], $traces[0]['properties']);
}

Expand Down
38 changes: 7 additions & 31 deletions pkg/enqueue/Client/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,13 @@

class Config
{
const PARAMETER_TOPIC_NAME = 'enqueue.topic_name';
const PARAMETER_COMMAND_NAME = 'enqueue.command_name';
const PARAMETER_PROCESSOR_NAME = 'enqueue.processor_name';

/**
* @deprecated
*/
const PARAMETER_PROCESSOR_QUEUE_NAME = 'enqueue.processor_queue_name';

const DEFAULT_PROCESSOR_QUEUE_NAME = 'default';

/**
* @deprecated
*/
const COMMAND_TOPIC = '__command__';
const TOPIC = 'enqueue.topic';
const COMMAND = 'enqueue.command';
const PROCESSOR = 'enqueue.processor';
const EXPIRE = 'enqueue.expire';
const PRIORITY = 'enqueue.priority';
const DELAY = 'enqueue.delay';
const CONTENT_TYPE = 'enqueue.content_type';

/**
* @var string
Expand Down Expand Up @@ -118,22 +110,6 @@ public function getRouterProcessorName(): string
return $this->routerProcessorName;
}

/**
* @deprecated
*/
public function createTransportRouterTopicName(string $name): string
{
return strtolower(implode('.', array_filter([trim($this->prefix), trim($name)])));
}

/**
* @deprecated
*/
public function createTransportQueueName(string $name): string
{
return strtolower(implode('.', array_filter([trim($this->prefix), trim($this->appName), trim($name)])));
}

/**
* @deprecated
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public function onPreReceived(Context $context)
$message = $context->getInteropMessage();
$queue = $context->getInteropQueue();

if ($message->getProperty(Config::PARAMETER_TOPIC_NAME)) {
if ($message->getProperty(Config::TOPIC)) {
return;
}
if ($message->getProperty(Config::PARAMETER_COMMAND_NAME)) {
if ($message->getProperty(Config::COMMAND)) {
return;
}
if ($message->getProperty(Config::PARAMETER_PROCESSOR_NAME)) {
if ($message->getProperty(Config::PROCESSOR)) {
return;
}

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

$route = $this->queueToRouteMap[$queue->getQueueName()];
$message->setProperty(Config::PARAMETER_PROCESSOR_NAME, $route->getProcessor());
$message->setProperty(Config::PARAMETER_COMMAND_NAME, $route->getSource());
$message->setProperty(Config::PROCESSOR, $route->getProcessor());
$message->setProperty(Config::COMMAND, $route->getSource());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(DriverInterface $driver)
public function onPreReceived(Context $context)
{
$message = $context->getInteropMessage();
if ($message->getProperty(Config::PARAMETER_PROCESSOR_NAME)) {
if ($message->getProperty(Config::PROCESSOR)) {
return;
}

Expand All @@ -39,7 +39,7 @@ public function onPreReceived(Context $context)
}

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

$context->getLogger()->debug(
'[SetRouterPropertiesExtension] '.
Expand Down
4 changes: 2 additions & 2 deletions pkg/enqueue/Client/DelegateProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public function __construct(ProcessorRegistryInterface $registry)
*/
public function process(InteropMessage $message, Context $context)
{
$processorName = $message->getProperty(Config::PARAMETER_PROCESSOR_NAME);
$processorName = $message->getProperty(Config::PROCESSOR);
if (false == $processorName) {
throw new \LogicException(sprintf(
'Got message without required parameter: "%s"',
Config::PARAMETER_PROCESSOR_NAME
Config::PROCESSOR
));
}

Expand Down
40 changes: 20 additions & 20 deletions pkg/enqueue/Client/Driver/GenericDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public function __construct(

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

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

public function sendToProcessor(Message $message): void
{
$topic = $message->getProperty(Config::PARAMETER_TOPIC_NAME);
$command = $message->getProperty(Config::PARAMETER_COMMAND_NAME);
$topic = $message->getProperty(Config::TOPIC);
$command = $message->getProperty(Config::COMMAND);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Expand Down
6 changes: 3 additions & 3 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->getConfig()->createTransportRouterTopicName($this->getConfig()->getRouterTopicName());
$routerExchange = $this->createTransportRouterTopicName($this->getConfig()->getRouterTopicName(), true);
$log('Declare router exchange: %s', $routerExchange);
$this->management->declareExchange($routerExchange, [
'type' => 'fanout',
'durable' => true,
'auto_delete' => false,
]);

$routerQueue = $this->getConfig()->createTransportQueueName($this->getConfig()->getRouterQueueName());
$routerQueue = $this->createTransportQueueName($this->getConfig()->getRouterQueueName(), true);
$log('Declare router queue: %s', $routerQueue);
$this->management->declareQueue($routerQueue, [
'auto_delete' => false,
Expand Down Expand Up @@ -169,7 +169,7 @@ protected function doSendToRouter(InteropProducer $producer, Destination $topic,
*/
protected function doSendToProcessor(InteropProducer $producer, InteropQueue $destination, InteropMessage $transportMessage): void
{
if ($delay = $transportMessage->getProperty('X-Enqueue-Delay')) {
if ($delay = $transportMessage->getProperty(Config::DELAY)) {
$producer->setDeliveryDelay(null);
$destination = $this->createDelayedTopic($destination);
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/enqueue/Client/DriverPreSend.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ public function getDriver(): DriverInterface

public function isEvent(): bool
{
return (bool) $this->message->getProperty(Config::PARAMETER_TOPIC_NAME);
return (bool) $this->message->getProperty(Config::TOPIC);
}

public function isCommand(): bool
{
return (bool) $this->message->getProperty(Config::PARAMETER_COMMAND_NAME);
return (bool) $this->message->getProperty(Config::COMMAND);
}

public function getCommand(): string
{
return $this->message->getProperty(Config::PARAMETER_COMMAND_NAME);
return $this->message->getProperty(Config::COMMAND);
}

public function getTopic(): string
{
return $this->message->getProperty(Config::PARAMETER_TOPIC_NAME);
return $this->message->getProperty(Config::TOPIC);
}
}
8 changes: 4 additions & 4 deletions pkg/enqueue/Client/PostSend.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ public function getDriver(): DriverInterface

public function isEvent(): bool
{
return (bool) $this->message->getProperty(Config::PARAMETER_TOPIC_NAME);
return (bool) $this->message->getProperty(Config::TOPIC);
}

public function isCommand(): bool
{
return (bool) $this->message->getProperty(Config::PARAMETER_COMMAND_NAME);
return (bool) $this->message->getProperty(Config::COMMAND);
}

public function getCommand(): string
{
return $this->message->getProperty(Config::PARAMETER_COMMAND_NAME);
return $this->message->getProperty(Config::COMMAND);
}

public function getTopic(): string
{
return $this->message->getProperty(Config::PARAMETER_TOPIC_NAME);
return $this->message->getProperty(Config::TOPIC);
}
}
8 changes: 4 additions & 4 deletions pkg/enqueue/Client/Producer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function sendEvent(string $topic, $message): void
$this->extension->onPreSendEvent($preSend);

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

$this->doSend($message);
}
Expand Down Expand Up @@ -79,7 +79,7 @@ public function sendCommand(string $command, $message, bool $needReply = false):
}
}

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

$this->doSend($message);
Expand All @@ -103,8 +103,8 @@ private function doSend(Message $message): void
));
}

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

if (!$message->getMessageId()) {
Expand Down
Loading