From 3383463ff3a285fd315e081729dc55d0e0aa3c8e Mon Sep 17 00:00:00 2001 From: Michiel Boeckaert Date: Tue, 5 Sep 2017 09:22:22 +0200 Subject: [PATCH 01/13] docs cli_commands.md add . --- docs/bundle/cli_commands.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/bundle/cli_commands.md b/docs/bundle/cli_commands.md index 0e89f1256..e6eb497a2 100644 --- a/docs/bundle/cli_commands.md +++ b/docs/bundle/cli_commands.md @@ -94,7 +94,7 @@ Help: ## enqueue:queues ``` -/bin/console enqueue:queues --help +./bin/console enqueue:queues --help Usage: enqueue:queues enq:m:q @@ -168,4 +168,4 @@ Help: A worker that consumes message from a broker. To use this broker you have to explicitly set a queue to consume from and a message processor service ``` -[back to index](../index.md) \ No newline at end of file +[back to index](../index.md) From 4ea1a5141f32383b49bb1feebedf90ef1701aeb8 Mon Sep 17 00:00:00 2001 From: Miliooo Date: Tue, 5 Sep 2017 13:51:52 +0200 Subject: [PATCH 02/13] update profiler layout --- .../Resources/views/Icon/icon.svg | 9 ++++ .../Resources/views/Profiler/panel.html.twig | 45 +++++++++++++------ 2 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 pkg/enqueue-bundle/Resources/views/Icon/icon.svg diff --git a/pkg/enqueue-bundle/Resources/views/Icon/icon.svg b/pkg/enqueue-bundle/Resources/views/Icon/icon.svg new file mode 100644 index 000000000..6a3179b4e --- /dev/null +++ b/pkg/enqueue-bundle/Resources/views/Icon/icon.svg @@ -0,0 +1,9 @@ + + + + diff --git a/pkg/enqueue-bundle/Resources/views/Profiler/panel.html.twig b/pkg/enqueue-bundle/Resources/views/Profiler/panel.html.twig index f0e2ca9f8..a8f783dfc 100644 --- a/pkg/enqueue-bundle/Resources/views/Profiler/panel.html.twig +++ b/pkg/enqueue-bundle/Resources/views/Profiler/panel.html.twig @@ -1,10 +1,27 @@ {% extends '@WebProfiler/Profiler/layout.html.twig' %} {% block toolbar %} + {% if collector.sentMessages|length > 0 %} + {% set icon %} + {{ include('@Enqueue/Icon/icon.svg') }} + + {{ collector.sentMessages|length }} + {% endset %} + + {% set text %} +
+ Sent messages + {{ collector.sentMessages|length }} +
+ {% endset %} + + {{ include('@WebProfiler/Profiler/toolbar_item.html.twig', { 'link': true }) }} + {% endif %} {% endblock %} {% block menu %} + {{ include('@Enqueue/Icon/icon.svg') }} Message Queue {% endblock %} @@ -13,19 +30,19 @@

Sent messages

- - - - - - + + + + + + - {% for sentMessage in collector.sentMessages %} - - - - + + + - - {% endfor %} + + + {% endfor %}
#TopicMessagePriority
#TopicMessagePriority
{{ loop.index }}{{ sentMessage.topic }} + {% for sentMessage in collector.sentMessages %} +
{{ loop.index }}{{ sentMessage.topic }} - {{ collector.prettyPrintPriority(sentMessage.priority) }}
{{ collector.prettyPrintPriority(sentMessage.priority) }}
From 30dbf4bebcfe87c3e50f6442ffecae1b65a20665 Mon Sep 17 00:00:00 2001 From: Alexander Kozienko Date: Fri, 8 Sep 2017 11:04:15 +0300 Subject: [PATCH 03/13] fs polling interval --- pkg/fs/FsConnectionFactory.php | 9 +++- pkg/fs/FsConsumer.php | 45 +++++++++++++++++-- pkg/fs/FsContext.php | 17 ++++++- pkg/fs/Symfony/FsTransportFactory.php | 5 +++ .../Tests/FsConnectionFactoryConfigTest.php | 7 +++ pkg/fs/Tests/FsConsumerTest.php | 8 ++++ pkg/fs/Tests/FsContextTest.php | 14 ++++++ .../Tests/Symfony/FsTransportFactoryTest.php | 5 +++ 8 files changed, 103 insertions(+), 7 deletions(-) diff --git a/pkg/fs/FsConnectionFactory.php b/pkg/fs/FsConnectionFactory.php index 8353db497..e078555fe 100644 --- a/pkg/fs/FsConnectionFactory.php +++ b/pkg/fs/FsConnectionFactory.php @@ -18,6 +18,7 @@ class FsConnectionFactory implements PsrConnectionFactory * 'path' => 'the directory where all queue\topic files remain. For example /home/foo/enqueue', * 'pre_fetch_count' => 'Integer. Defines how many messages to fetch from the file.', * 'chmod' => 'Defines a mode the files are created with', + * 'polling_interval' => 'How often query for new messages, default 1000 (milliseconds)', * ] * * or @@ -48,7 +49,12 @@ public function __construct($config = 'file://') */ public function createContext() { - return new FsContext($this->config['path'], $this->config['pre_fetch_count'], $this->config['chmod']); + return new FsContext( + $this->config['path'], + $this->config['pre_fetch_count'], + $this->config['chmod'], + $this->config['polling_interval'] + ); } /** @@ -99,6 +105,7 @@ private function defaultConfig() 'path' => null, 'pre_fetch_count' => 1, 'chmod' => 0600, + 'polling_interval' => 1000, ]; } } diff --git a/pkg/fs/FsConsumer.php b/pkg/fs/FsConsumer.php index c9ef71552..a3301600f 100644 --- a/pkg/fs/FsConsumer.php +++ b/pkg/fs/FsConsumer.php @@ -28,6 +28,11 @@ class FsConsumer implements PsrConsumer */ private $preFetchedMessages; + /** + * @var int microseconds + */ + private $pollingInterval = 1000000; + /** * @param FsContext $context * @param FsDestination $destination @@ -42,6 +47,26 @@ public function __construct(FsContext $context, FsDestination $destination, $pre $this->preFetchedMessages = []; } + /** + * Set polling interval in milliseconds. + * + * @param int $msec + */ + public function setPollingInterval($msec) + { + $this->pollingInterval = $msec * 1000; + } + + /** + * Get polling interval in milliseconds. + * + * @return int + */ + public function getPollingInterval() + { + return (int) $this->pollingInterval / 1000; + } + /** * {@inheritdoc} * @@ -59,13 +84,25 @@ public function getQueue() */ public function receive($timeout = 0) { - $end = microtime(true) + ($timeout / 1000); - while (0 === $timeout || microtime(true) < $end) { - if ($message = $this->receiveNoWait()) { + $timeout /= 1000; + $startAt = microtime(true); + + while (true) { + $message = $this->receiveNoWait(); + + if ($message) { return $message; } - usleep(100); + if ($timeout && (microtime(true) - $startAt) >= $timeout) { + return; + } + + usleep($this->pollingInterval); + + if ($timeout && (microtime(true) - $startAt) >= $timeout) { + return; + } } } diff --git a/pkg/fs/FsContext.php b/pkg/fs/FsContext.php index a711e88e7..542975545 100644 --- a/pkg/fs/FsContext.php +++ b/pkg/fs/FsContext.php @@ -32,12 +32,18 @@ class FsContext implements PsrContext */ private $lockHandlers; + /** + * @var null + */ + private $pollingInterval; + /** * @param string $storeDir * @param int $preFetchCount * @param int $chmod + * @param null $pollingInterval */ - public function __construct($storeDir, $preFetchCount, $chmod) + public function __construct($storeDir, $preFetchCount, $chmod, $pollingInterval = null) { $fs = new Filesystem(); $fs->mkdir($storeDir); @@ -45,6 +51,7 @@ public function __construct($storeDir, $preFetchCount, $chmod) $this->storeDir = $storeDir; $this->preFetchCount = $preFetchCount; $this->chmod = $chmod; + $this->pollingInterval = $pollingInterval; $this->lockHandlers = []; } @@ -160,7 +167,13 @@ public function createConsumer(PsrDestination $destination) { InvalidDestinationException::assertDestinationInstanceOf($destination, FsDestination::class); - return new FsConsumer($this, $destination, $this->preFetchCount); + $consumer = new FsConsumer($this, $destination, $this->preFetchCount); + + if ($this->pollingInterval) { + $consumer->setPollingInterval($this->pollingInterval); + } + + return $consumer; } public function close() diff --git a/pkg/fs/Symfony/FsTransportFactory.php b/pkg/fs/Symfony/FsTransportFactory.php index 482cddc87..4bd4f7216 100644 --- a/pkg/fs/Symfony/FsTransportFactory.php +++ b/pkg/fs/Symfony/FsTransportFactory.php @@ -56,6 +56,11 @@ public function addConfiguration(ArrayNodeDefinition $builder) ->defaultValue(0600) ->info('The queue files are created with this given permissions if not exist.') ->end() + ->integerNode('polling_interval') + ->defaultValue(1000) + ->min(100) + ->info('How often query for new messages.') + ->end() ; } diff --git a/pkg/fs/Tests/FsConnectionFactoryConfigTest.php b/pkg/fs/Tests/FsConnectionFactoryConfigTest.php index 71c52c2d0..83c33227b 100644 --- a/pkg/fs/Tests/FsConnectionFactoryConfigTest.php +++ b/pkg/fs/Tests/FsConnectionFactoryConfigTest.php @@ -58,6 +58,7 @@ public static function provideConfigs() 'path' => sys_get_temp_dir().'/enqueue', 'pre_fetch_count' => 1, 'chmod' => 0600, + 'polling_interval' => '1000', ], ]; @@ -67,6 +68,7 @@ public static function provideConfigs() 'path' => sys_get_temp_dir().'/enqueue', 'pre_fetch_count' => 1, 'chmod' => 0600, + 'polling_interval' => '1000', ], ]; @@ -76,6 +78,7 @@ public static function provideConfigs() 'path' => sys_get_temp_dir().'/enqueue', 'pre_fetch_count' => 1, 'chmod' => 0600, + 'polling_interval' => '1000', ], ]; @@ -85,6 +88,7 @@ public static function provideConfigs() 'path' => sys_get_temp_dir().'/enqueue', 'pre_fetch_count' => 1, 'chmod' => 0600, + 'polling_interval' => '1000', ], ]; @@ -94,6 +98,7 @@ public static function provideConfigs() 'path' => '/foo/bar/baz', 'pre_fetch_count' => 1, 'chmod' => 0600, + 'polling_interval' => '1000', ], ]; @@ -103,6 +108,7 @@ public static function provideConfigs() 'path' => '/foo/bar/baz', 'pre_fetch_count' => 1, 'chmod' => 0600, + 'polling_interval' => '1000', ], ]; @@ -112,6 +118,7 @@ public static function provideConfigs() 'path' => '/foo/bar/baz', 'pre_fetch_count' => 100, 'chmod' => 0666, + 'polling_interval' => '1000', ], ]; } diff --git a/pkg/fs/Tests/FsConsumerTest.php b/pkg/fs/Tests/FsConsumerTest.php index 408cfd2cb..b3f14266c 100644 --- a/pkg/fs/Tests/FsConsumerTest.php +++ b/pkg/fs/Tests/FsConsumerTest.php @@ -64,6 +64,14 @@ public function testShouldDoNothingOnReject() $consumer->reject(new FsMessage()); } + public function testCouldSetAndGetPollingInterval() + { + $consumer = new FsConsumer($this->createContextMock(), new FsDestination(TempFile::generate()), 123); + $consumer->setPollingInterval(123456); + + $this->assertEquals(123456, $consumer->getPollingInterval()); + } + public function testShouldSendSameMessageToDestinationOnReQueue() { $message = new FsMessage(); diff --git a/pkg/fs/Tests/FsContextTest.php b/pkg/fs/Tests/FsContextTest.php index 3c3c53c59..5ce324a49 100644 --- a/pkg/fs/Tests/FsContextTest.php +++ b/pkg/fs/Tests/FsContextTest.php @@ -233,4 +233,18 @@ public function testShouldCreateFileOnFilesystemIfNotExistOnDeclareDestination() unlink($tmpFile); } + + public function testShouldCreateMessageConsumerAndSetPollingInterval() + { + $tmpFile = new TempFile(sys_get_temp_dir().'/foo'); + + $context = new FsContext(sys_get_temp_dir(), 1, 0666, 123456); + + $queue = $context->createQueue($tmpFile->getFilename()); + + $consumer = $context->createConsumer($queue); + + $this->assertInstanceOf(FsConsumer::class, $consumer); + $this->assertEquals(123456, $consumer->getPollingInterval()); + } } diff --git a/pkg/fs/Tests/Symfony/FsTransportFactoryTest.php b/pkg/fs/Tests/Symfony/FsTransportFactoryTest.php index c135a866d..7f5ecc038 100644 --- a/pkg/fs/Tests/Symfony/FsTransportFactoryTest.php +++ b/pkg/fs/Tests/Symfony/FsTransportFactoryTest.php @@ -52,6 +52,7 @@ public function testShouldAllowAddConfiguration() 'path' => sys_get_temp_dir(), 'pre_fetch_count' => 1, 'chmod' => 0600, + 'polling_interval' => 1000, ], $config); } @@ -69,6 +70,7 @@ public function testShouldAllowAddConfigurationAsString() 'dsn' => 'fileDSN', 'pre_fetch_count' => 1, 'chmod' => 0600, + 'polling_interval' => 1000, ], $config); } @@ -82,6 +84,7 @@ public function testShouldCreateConnectionFactory() 'path' => sys_get_temp_dir(), 'pre_fetch_count' => 1, 'chmod' => 0600, + 'polling_interval' => 1000, ]); $this->assertTrue($container->hasDefinition($serviceId)); @@ -91,6 +94,7 @@ public function testShouldCreateConnectionFactory() 'path' => sys_get_temp_dir(), 'pre_fetch_count' => 1, 'chmod' => 0600, + 'polling_interval' => 1000, ]], $factory->getArguments()); } @@ -120,6 +124,7 @@ public function testShouldCreateContext() 'path' => sys_get_temp_dir(), 'pre_fetch_count' => 1, 'chmod' => 0600, + 'polling_interval' => 1000, ]); $this->assertEquals('enqueue.transport.fs.context', $serviceId); From db7e05d45251644bb3d07c821d5f6d49a991aa25 Mon Sep 17 00:00:00 2001 From: Alexander Kozienko Date: Fri, 8 Sep 2017 11:13:22 +0300 Subject: [PATCH 04/13] fs polling interval --- pkg/fs/FsConnectionFactory.php | 4 ++-- pkg/fs/FsConsumer.php | 2 +- pkg/fs/Symfony/FsTransportFactory.php | 4 ++-- pkg/fs/Tests/FsConnectionFactoryConfigTest.php | 14 +++++++------- pkg/fs/Tests/Symfony/FsTransportFactoryTest.php | 10 +++++----- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/pkg/fs/FsConnectionFactory.php b/pkg/fs/FsConnectionFactory.php index e078555fe..f155c9df9 100644 --- a/pkg/fs/FsConnectionFactory.php +++ b/pkg/fs/FsConnectionFactory.php @@ -18,7 +18,7 @@ class FsConnectionFactory implements PsrConnectionFactory * 'path' => 'the directory where all queue\topic files remain. For example /home/foo/enqueue', * 'pre_fetch_count' => 'Integer. Defines how many messages to fetch from the file.', * 'chmod' => 'Defines a mode the files are created with', - * 'polling_interval' => 'How often query for new messages, default 1000 (milliseconds)', + * 'polling_interval' => 'How often query for new messages, default 100 (milliseconds)', * ] * * or @@ -105,7 +105,7 @@ private function defaultConfig() 'path' => null, 'pre_fetch_count' => 1, 'chmod' => 0600, - 'polling_interval' => 1000, + 'polling_interval' => 100, ]; } } diff --git a/pkg/fs/FsConsumer.php b/pkg/fs/FsConsumer.php index a3301600f..1bd36c498 100644 --- a/pkg/fs/FsConsumer.php +++ b/pkg/fs/FsConsumer.php @@ -31,7 +31,7 @@ class FsConsumer implements PsrConsumer /** * @var int microseconds */ - private $pollingInterval = 1000000; + private $pollingInterval = 100000; /** * @param FsContext $context diff --git a/pkg/fs/Symfony/FsTransportFactory.php b/pkg/fs/Symfony/FsTransportFactory.php index 4bd4f7216..9908f8914 100644 --- a/pkg/fs/Symfony/FsTransportFactory.php +++ b/pkg/fs/Symfony/FsTransportFactory.php @@ -57,8 +57,8 @@ public function addConfiguration(ArrayNodeDefinition $builder) ->info('The queue files are created with this given permissions if not exist.') ->end() ->integerNode('polling_interval') - ->defaultValue(1000) - ->min(100) + ->defaultValue(100) + ->min(50) ->info('How often query for new messages.') ->end() ; diff --git a/pkg/fs/Tests/FsConnectionFactoryConfigTest.php b/pkg/fs/Tests/FsConnectionFactoryConfigTest.php index 83c33227b..a42ede8c6 100644 --- a/pkg/fs/Tests/FsConnectionFactoryConfigTest.php +++ b/pkg/fs/Tests/FsConnectionFactoryConfigTest.php @@ -58,7 +58,7 @@ public static function provideConfigs() 'path' => sys_get_temp_dir().'/enqueue', 'pre_fetch_count' => 1, 'chmod' => 0600, - 'polling_interval' => '1000', + 'polling_interval' => 100, ], ]; @@ -68,7 +68,7 @@ public static function provideConfigs() 'path' => sys_get_temp_dir().'/enqueue', 'pre_fetch_count' => 1, 'chmod' => 0600, - 'polling_interval' => '1000', + 'polling_interval' => 100, ], ]; @@ -78,7 +78,7 @@ public static function provideConfigs() 'path' => sys_get_temp_dir().'/enqueue', 'pre_fetch_count' => 1, 'chmod' => 0600, - 'polling_interval' => '1000', + 'polling_interval' => 100, ], ]; @@ -88,7 +88,7 @@ public static function provideConfigs() 'path' => sys_get_temp_dir().'/enqueue', 'pre_fetch_count' => 1, 'chmod' => 0600, - 'polling_interval' => '1000', + 'polling_interval' => 100, ], ]; @@ -98,7 +98,7 @@ public static function provideConfigs() 'path' => '/foo/bar/baz', 'pre_fetch_count' => 1, 'chmod' => 0600, - 'polling_interval' => '1000', + 'polling_interval' => 100, ], ]; @@ -108,7 +108,7 @@ public static function provideConfigs() 'path' => '/foo/bar/baz', 'pre_fetch_count' => 1, 'chmod' => 0600, - 'polling_interval' => '1000', + 'polling_interval' => 100, ], ]; @@ -118,7 +118,7 @@ public static function provideConfigs() 'path' => '/foo/bar/baz', 'pre_fetch_count' => 100, 'chmod' => 0666, - 'polling_interval' => '1000', + 'polling_interval' => 100, ], ]; } diff --git a/pkg/fs/Tests/Symfony/FsTransportFactoryTest.php b/pkg/fs/Tests/Symfony/FsTransportFactoryTest.php index 7f5ecc038..1fccf154e 100644 --- a/pkg/fs/Tests/Symfony/FsTransportFactoryTest.php +++ b/pkg/fs/Tests/Symfony/FsTransportFactoryTest.php @@ -52,7 +52,7 @@ public function testShouldAllowAddConfiguration() 'path' => sys_get_temp_dir(), 'pre_fetch_count' => 1, 'chmod' => 0600, - 'polling_interval' => 1000, + 'polling_interval' => 100, ], $config); } @@ -70,7 +70,7 @@ public function testShouldAllowAddConfigurationAsString() 'dsn' => 'fileDSN', 'pre_fetch_count' => 1, 'chmod' => 0600, - 'polling_interval' => 1000, + 'polling_interval' => 100, ], $config); } @@ -84,7 +84,7 @@ public function testShouldCreateConnectionFactory() 'path' => sys_get_temp_dir(), 'pre_fetch_count' => 1, 'chmod' => 0600, - 'polling_interval' => 1000, + 'polling_interval' => 100, ]); $this->assertTrue($container->hasDefinition($serviceId)); @@ -94,7 +94,7 @@ public function testShouldCreateConnectionFactory() 'path' => sys_get_temp_dir(), 'pre_fetch_count' => 1, 'chmod' => 0600, - 'polling_interval' => 1000, + 'polling_interval' => 100, ]], $factory->getArguments()); } @@ -124,7 +124,7 @@ public function testShouldCreateContext() 'path' => sys_get_temp_dir(), 'pre_fetch_count' => 1, 'chmod' => 0600, - 'polling_interval' => 1000, + 'polling_interval' => 100, ]); $this->assertEquals('enqueue.transport.fs.context', $serviceId); From 337bb0080f16ecbaf8e3a1e6a267e5a78969666e Mon Sep 17 00:00:00 2001 From: Alexander Kozienko Date: Fri, 8 Sep 2017 11:45:26 +0300 Subject: [PATCH 05/13] fix travis --- bin/test | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/test b/bin/test index 6641bc743..ea5789a92 100755 --- a/bin/test +++ b/bin/test @@ -23,9 +23,9 @@ function waitForService() waitForService rabbitmq 5672 50 waitForService mysql 3306 50 waitForService redis 6379 50 -waitForService beanstalkd 11300 -waitForService gearmand 4730 -waitForService kafka 9092 +waitForService beanstalkd 11300 50 +waitForService gearmand 4730 50 +waitForService kafka 9092 50 php pkg/job-queue/Tests/Functional/app/console doctrine:database:create php pkg/job-queue/Tests/Functional/app/console doctrine:schema:update --force From 2deab7e147363378d89f54dfbd396b52bf1e520b Mon Sep 17 00:00:00 2001 From: Alexander Kozienko Date: Fri, 8 Sep 2017 15:42:18 +0300 Subject: [PATCH 06/13] queue consumer options --- .../DependencyInjection/Configuration.php | 12 +++++ .../DependencyInjection/EnqueueExtension.php | 13 +++++ .../DependencyInjection/ConfigurationTest.php | 21 ++++++++ .../EnqueueExtensionTest.php | 24 +++++++++ pkg/enqueue/Consumption/QueueConsumer.php | 32 +++++++++++ .../Symfony/Client/ConsumeMessagesCommand.php | 5 ++ .../Consumption/ConsumeMessagesCommand.php | 4 ++ .../ContainerAwareConsumeMessagesCommand.php | 4 ++ .../QueueConsumerOptionsCommandTrait.php | 36 +++++++++++++ .../Tests/Consumption/QueueConsumerTest.php | 18 +++++++ .../Mock/QueueConsumerOptionsCommand.php | 38 +++++++++++++ .../QueueConsumerOptionsCommandTraitTest.php | 53 +++++++++++++++++++ 12 files changed, 260 insertions(+) create mode 100644 pkg/enqueue/Symfony/Consumption/QueueConsumerOptionsCommandTrait.php create mode 100644 pkg/enqueue/Tests/Symfony/Consumption/Mock/QueueConsumerOptionsCommand.php create mode 100644 pkg/enqueue/Tests/Symfony/Consumption/QueueConsumerOptionsCommandTraitTest.php diff --git a/pkg/enqueue-bundle/DependencyInjection/Configuration.php b/pkg/enqueue-bundle/DependencyInjection/Configuration.php index c5c0877f5..92686d12e 100644 --- a/pkg/enqueue-bundle/DependencyInjection/Configuration.php +++ b/pkg/enqueue-bundle/DependencyInjection/Configuration.php @@ -50,6 +50,18 @@ public function getConfigTreeBuilder() ->scalarNode('default_processor_queue')->defaultValue(Config::DEFAULT_PROCESSOR_QUEUE_NAME)->cannotBeEmpty()->end() ->integerNode('redelivered_delay_time')->min(0)->defaultValue(0)->end() ->end()->end() + ->arrayNode('consumption')->addDefaultsIfNotSet()->children() + ->integerNode('idle_timeout') + ->min(0) + ->defaultValue(0) + ->info('the time in milliseconds queue consumer waits if no message received') + ->end() + ->integerNode('receive_timeout') + ->min(0) + ->defaultValue(100) + ->info('the time in milliseconds queue consumer waits for a message (100 ms by default)') + ->end() + ->end()->end() ->booleanNode('job')->defaultFalse()->end() ->arrayNode('async_events') ->addDefaultsIfNotSet() diff --git a/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php b/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php index f138d60fa..42e37ce33 100644 --- a/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php +++ b/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php @@ -110,6 +110,19 @@ public function load(array $configs, ContainerBuilder $container) } } + // configure queue consumer + $container->getDefinition('enqueue.consumption.queue_consumer') + ->setArgument(2, $config['consumption']['idle_timeout']) + ->setArgument(3, $config['consumption']['receive_timeout']) + ; + + if ($container->hasDefinition('enqueue.client.queue_consumer')) { + $container->getDefinition('enqueue.client.queue_consumer') + ->setArgument(2, $config['consumption']['idle_timeout']) + ->setArgument(3, $config['consumption']['receive_timeout']) + ; + } + if ($config['job']) { if (false == class_exists(Job::class)) { throw new \LogicException('Seems "enqueue/job-queue" is not installed. Please fix this issue.'); diff --git a/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/ConfigurationTest.php b/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/ConfigurationTest.php index 53e54819d..8d8ba99cc 100644 --- a/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/ConfigurationTest.php @@ -423,4 +423,25 @@ public function testShouldAllowEnableAsyncEvents() ], ], $config); } + + public function testShouldAllowConfigureConsumption() + { + $configuration = new Configuration([]); + + $processor = new Processor(); + $config = $processor->processConfiguration($configuration, [[ + 'transport' => [], + 'consumption' => [ + 'idle_timeout' => 123, + 'receive_timeout' => 456, + ], + ]]); + + $this->assertArraySubset([ + 'consumption' => [ + 'idle_timeout' => 123, + 'receive_timeout' => 456, + ], + ], $config); + } } diff --git a/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/EnqueueExtensionTest.php b/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/EnqueueExtensionTest.php index b522ccfad..fdfaac125 100644 --- a/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/EnqueueExtensionTest.php +++ b/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/EnqueueExtensionTest.php @@ -535,4 +535,28 @@ public function testShouldNotAddJobQueueEntityMappingIfDoctrineBundleIsNotRegist $this->assertSame([], $container->getExtensionConfig('doctrine')); } + + public function testShouldConfigureQueueConsumer() + { + $container = new ContainerBuilder(); + + $extension = new EnqueueExtension(); + $extension->load([[ + 'client' => [], + 'transport' => [ + ], + 'consumption' => [ + 'idle-timeout' => 123, + 'receive-timeout' => 456, + ], + ]], $container); + + $def = $container->getDefinition('enqueue.consumption.queue_consumer'); + $this->assertSame(123, $def->getArgument(2)); + $this->assertSame(456, $def->getArgument(3)); + + $def = $container->getDefinition('enqueue.client.queue_consumer'); + $this->assertSame(123, $def->getArgument(2)); + $this->assertSame(456, $def->getArgument(3)); + } } diff --git a/pkg/enqueue/Consumption/QueueConsumer.php b/pkg/enqueue/Consumption/QueueConsumer.php index 8d3f93a00..fe2aafcee 100644 --- a/pkg/enqueue/Consumption/QueueConsumer.php +++ b/pkg/enqueue/Consumption/QueueConsumer.php @@ -63,6 +63,38 @@ public function __construct( $this->boundProcessors = []; } + /** + * @param int $timeout + */ + public function setIdleTimeout($timeout) + { + $this->idleTimeout = (int) $timeout; + } + + /** + * @return int + */ + public function getIdleTimeout() + { + return $this->idleTimeout; + } + + /** + * @param int $timeout + */ + public function setReceiveTimeout($timeout) + { + $this->receiveTimeout = (int) $timeout; + } + + /** + * @return int + */ + public function getReceiveTimeout() + { + return $this->receiveTimeout; + } + /** * @return PsrContext */ diff --git a/pkg/enqueue/Symfony/Client/ConsumeMessagesCommand.php b/pkg/enqueue/Symfony/Client/ConsumeMessagesCommand.php index 692c0d674..2ec98e2b3 100644 --- a/pkg/enqueue/Symfony/Client/ConsumeMessagesCommand.php +++ b/pkg/enqueue/Symfony/Client/ConsumeMessagesCommand.php @@ -9,6 +9,7 @@ use Enqueue\Consumption\Extension\LoggerExtension; use Enqueue\Consumption\QueueConsumer; use Enqueue\Symfony\Consumption\LimitsExtensionsCommandTrait; +use Enqueue\Symfony\Consumption\QueueConsumerOptionsCommandTrait; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -19,6 +20,7 @@ class ConsumeMessagesCommand extends Command { use LimitsExtensionsCommandTrait; use SetupBrokerExtensionCommandTrait; + use QueueConsumerOptionsCommandTrait; /** * @var QueueConsumer @@ -67,6 +69,7 @@ protected function configure() { $this->configureLimitsExtensions(); $this->configureSetupBrokerExtension(); + $this->configureQueueConsumerOptions(); $this ->setName('enqueue:consume') @@ -83,6 +86,8 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $this->setQueueConsumerOptions($this->consumer, $input); + $queueMetas = []; if ($clientQueueNames = $input->getArgument('client-queue-names')) { foreach ($clientQueueNames as $clientQueueName) { diff --git a/pkg/enqueue/Symfony/Consumption/ConsumeMessagesCommand.php b/pkg/enqueue/Symfony/Consumption/ConsumeMessagesCommand.php index 9de5805aa..c2c7695f1 100644 --- a/pkg/enqueue/Symfony/Consumption/ConsumeMessagesCommand.php +++ b/pkg/enqueue/Symfony/Consumption/ConsumeMessagesCommand.php @@ -16,6 +16,7 @@ class ConsumeMessagesCommand extends Command implements ContainerAwareInterface { use ContainerAwareTrait; use LimitsExtensionsCommandTrait; + use QueueConsumerOptionsCommandTrait; /** * @var QueueConsumer @@ -38,6 +39,7 @@ public function __construct(QueueConsumer $consumer) protected function configure() { $this->configureLimitsExtensions(); + $this->configureQueueConsumerOptions(); $this ->setName('enqueue:transport:consume') @@ -51,6 +53,8 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $this->setQueueConsumerOptions($this->consumer, $input); + $extensions = $this->getLimitsExtensions($input, $output); array_unshift($extensions, new LoggerExtension(new ConsoleLogger($output))); diff --git a/pkg/enqueue/Symfony/Consumption/ContainerAwareConsumeMessagesCommand.php b/pkg/enqueue/Symfony/Consumption/ContainerAwareConsumeMessagesCommand.php index 16020ccd3..297dfa58d 100644 --- a/pkg/enqueue/Symfony/Consumption/ContainerAwareConsumeMessagesCommand.php +++ b/pkg/enqueue/Symfony/Consumption/ContainerAwareConsumeMessagesCommand.php @@ -20,6 +20,7 @@ class ContainerAwareConsumeMessagesCommand extends Command implements ContainerA { use ContainerAwareTrait; use LimitsExtensionsCommandTrait; + use QueueConsumerOptionsCommandTrait; /** * @var QueueConsumer @@ -44,6 +45,7 @@ public function __construct(QueueConsumer $consumer) protected function configure() { $this->configureLimitsExtensions(); + $this->configureQueueConsumerOptions(); $this ->setName('enqueue:transport:consume') @@ -60,6 +62,8 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $this->setQueueConsumerOptions($this->consumer, $input); + /** @var PsrProcessor $processor */ $processor = $this->container->get($input->getArgument('processor-service')); if (false == $processor instanceof PsrProcessor) { diff --git a/pkg/enqueue/Symfony/Consumption/QueueConsumerOptionsCommandTrait.php b/pkg/enqueue/Symfony/Consumption/QueueConsumerOptionsCommandTrait.php new file mode 100644 index 000000000..8f1eae00b --- /dev/null +++ b/pkg/enqueue/Symfony/Consumption/QueueConsumerOptionsCommandTrait.php @@ -0,0 +1,36 @@ +addOption('idle-timeout', null, InputOption::VALUE_REQUIRED, 'The time in milliseconds queue consumer waits if no message received.') + ->addOption('receive-timeout', null, InputOption::VALUE_REQUIRED, 'The time in milliseconds queue consumer waits for a message.') + ; + } + + /** + * @param QueueConsumer $consumer + * @param InputInterface $input + */ + protected function setQueueConsumerOptions(QueueConsumer $consumer, InputInterface $input) + { + if (null !== $idleTimeout = $input->getOption('idle-timeout')) { + $consumer->setIdleTimeout((int) $idleTimeout); + } + + if (null !== $receiveTimeout = $input->getOption('receive-timeout')) { + $consumer->setReceiveTimeout((int) $receiveTimeout); + } + } +} diff --git a/pkg/enqueue/Tests/Consumption/QueueConsumerTest.php b/pkg/enqueue/Tests/Consumption/QueueConsumerTest.php index fa3b304e3..196f75598 100644 --- a/pkg/enqueue/Tests/Consumption/QueueConsumerTest.php +++ b/pkg/enqueue/Tests/Consumption/QueueConsumerTest.php @@ -108,6 +108,24 @@ public function testThrowIfProcessorNeitherInstanceOfProcessorNorCallable() $consumer->bind(new NullQueue(''), new \stdClass()); } + public function testCouldSetGetIdleTimeout() + { + $consumer = new QueueConsumer($this->createPsrContextStub(), null, 0); + + $consumer->setIdleTimeout(123456); + + $this->assertSame(123456, $consumer->getIdleTimeout()); + } + + public function testCouldSetGetReceiveTimeout() + { + $consumer = new QueueConsumer($this->createPsrContextStub(), null, 0); + + $consumer->setReceiveTimeout(123456); + + $this->assertSame(123456, $consumer->getReceiveTimeout()); + } + public function testShouldAllowBindCallbackToQueueName() { $callback = function () { diff --git a/pkg/enqueue/Tests/Symfony/Consumption/Mock/QueueConsumerOptionsCommand.php b/pkg/enqueue/Tests/Symfony/Consumption/Mock/QueueConsumerOptionsCommand.php new file mode 100644 index 000000000..88a0d8cf2 --- /dev/null +++ b/pkg/enqueue/Tests/Symfony/Consumption/Mock/QueueConsumerOptionsCommand.php @@ -0,0 +1,38 @@ +consumer = $consumer; + } + + protected function configure() + { + parent::configure(); + + $this->configureQueueConsumerOptions(); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $this->setQueueConsumerOptions($this->consumer, $input); + } +} diff --git a/pkg/enqueue/Tests/Symfony/Consumption/QueueConsumerOptionsCommandTraitTest.php b/pkg/enqueue/Tests/Symfony/Consumption/QueueConsumerOptionsCommandTraitTest.php new file mode 100644 index 000000000..57106aa24 --- /dev/null +++ b/pkg/enqueue/Tests/Symfony/Consumption/QueueConsumerOptionsCommandTraitTest.php @@ -0,0 +1,53 @@ +createQueueConsumer()); + + $options = $trait->getDefinition()->getOptions(); + + $this->assertCount(2, $options); + $this->assertArrayHasKey('idle-timeout', $options); + $this->assertArrayHasKey('receive-timeout', $options); + } + + public function testShouldSetQueueConsumerOptions() + { + $consumer = $this->createQueueConsumer(); + $consumer + ->expects($this->once()) + ->method('setIdleTimeout') + ->with($this->identicalTo(123)) + ; + $consumer + ->expects($this->once()) + ->method('setReceiveTimeout') + ->with($this->identicalTo(456)) + ; + + $trait = new QueueConsumerOptionsCommand($consumer); + + $tester = new CommandTester($trait); + $tester->execute([ + '--idle-timeout' => '123', + '--receive-timeout' => '456', + ]); + } + + /** + * @return QueueConsumer|\PHPUnit_Framework_MockObject_MockObject|QueueConsumer + */ + private function createQueueConsumer() + { + return $this->createMock(QueueConsumer::class); + } +} From ad3782eb199013801db3a14c4c6923a74026e062 Mon Sep 17 00:00:00 2001 From: Alexander Kozienko Date: Fri, 8 Sep 2017 16:39:18 +0300 Subject: [PATCH 07/13] queue consumer options --- .../Tests/Symfony/Client/ConsumeMessagesCommandTest.php | 4 +++- .../Tests/Symfony/Consumption/ConsumeMessagesCommandTest.php | 4 +++- .../Consumption/ContainerAwareConsumeMessagesCommandTest.php | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/enqueue/Tests/Symfony/Client/ConsumeMessagesCommandTest.php b/pkg/enqueue/Tests/Symfony/Client/ConsumeMessagesCommandTest.php index 868c32c8f..b6017abdc 100644 --- a/pkg/enqueue/Tests/Symfony/Client/ConsumeMessagesCommandTest.php +++ b/pkg/enqueue/Tests/Symfony/Client/ConsumeMessagesCommandTest.php @@ -61,11 +61,13 @@ public function testShouldHaveExpectedOptions() $options = $command->getDefinition()->getOptions(); - $this->assertCount(4, $options); + $this->assertCount(6, $options); $this->assertArrayHasKey('memory-limit', $options); $this->assertArrayHasKey('message-limit', $options); $this->assertArrayHasKey('time-limit', $options); $this->assertArrayHasKey('setup-broker', $options); + $this->assertArrayHasKey('idle-timeout', $options); + $this->assertArrayHasKey('receive-timeout', $options); } public function testShouldHaveExpectedAttributes() diff --git a/pkg/enqueue/Tests/Symfony/Consumption/ConsumeMessagesCommandTest.php b/pkg/enqueue/Tests/Symfony/Consumption/ConsumeMessagesCommandTest.php index a08bb5572..d83505a0c 100644 --- a/pkg/enqueue/Tests/Symfony/Consumption/ConsumeMessagesCommandTest.php +++ b/pkg/enqueue/Tests/Symfony/Consumption/ConsumeMessagesCommandTest.php @@ -29,10 +29,12 @@ public function testShouldHaveExpectedOptions() $options = $command->getDefinition()->getOptions(); - $this->assertCount(3, $options); + $this->assertCount(5, $options); $this->assertArrayHasKey('memory-limit', $options); $this->assertArrayHasKey('message-limit', $options); $this->assertArrayHasKey('time-limit', $options); + $this->assertArrayHasKey('idle-timeout', $options); + $this->assertArrayHasKey('receive-timeout', $options); } public function testShouldHaveExpectedAttributes() diff --git a/pkg/enqueue/Tests/Symfony/Consumption/ContainerAwareConsumeMessagesCommandTest.php b/pkg/enqueue/Tests/Symfony/Consumption/ContainerAwareConsumeMessagesCommandTest.php index 87fbe559d..b451dc712 100644 --- a/pkg/enqueue/Tests/Symfony/Consumption/ContainerAwareConsumeMessagesCommandTest.php +++ b/pkg/enqueue/Tests/Symfony/Consumption/ContainerAwareConsumeMessagesCommandTest.php @@ -33,11 +33,13 @@ public function testShouldHaveExpectedOptions() $options = $command->getDefinition()->getOptions(); - $this->assertCount(4, $options); + $this->assertCount(6, $options); $this->assertArrayHasKey('memory-limit', $options); $this->assertArrayHasKey('message-limit', $options); $this->assertArrayHasKey('time-limit', $options); $this->assertArrayHasKey('queue', $options); + $this->assertArrayHasKey('idle-timeout', $options); + $this->assertArrayHasKey('receive-timeout', $options); } public function testShouldHaveExpectedAttributes() From 00de863260a18d7e65b3f52876c6567a017d71a7 Mon Sep 17 00:00:00 2001 From: Alexander Kozienko Date: Fri, 8 Sep 2017 16:44:39 +0300 Subject: [PATCH 08/13] queue consumer options --- .travis.yml | 2 +- .../Tests/Unit/DependencyInjection/EnqueueExtensionTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 680d8147f..e20f62bfe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,7 +49,7 @@ script: - if [ "$PHPSTAN" = true ]; then composer require "phpstan/phpstan:^0.8" ; php -d memory_limit=512M bin/phpstan analyse -l 1 -c phpstan.neon pkg/gps pkg/amqp-ext pkg/async-event-dispatcher pkg/dbal pkg/enqueue pkg/enqueue-bundle pkg/fs pkg/gearman pkg/job-queue pkg/null pkg/pheanstalk pkg/redis pkg/simple-client pkg/sqs pkg/stomp pkg/test pkg/rdkafka; fi - if [ "$PHP_CS_FIXER" = true ]; then IFS=$'\n'; COMMIT_SCA_FILES=($(git diff --name-only --diff-filter=ACMRTUXB "${TRAVIS_COMMIT_RANGE}")); unset IFS; fi - if [ "$PHP_CS_FIXER" = true ]; then ./bin/php-cs-fixer fix --config=.php_cs.dist -v --dry-run --stop-on-violation --using-cache=no --path-mode=intersection -- "${COMMIT_SCA_FILES[@]}"; fi - - if [ "$UNIT_TESTS" = true ]; then bin/phpunit --exclude-group=functional; fi + - if [ "$UNIT_TESTS" = true ]; then bin/phpunit --debug --exclude-group=functional; fi - if [ "$FUNCTIONAL_TESTS" = true ]; then bin/dev -t; fi notifications: diff --git a/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/EnqueueExtensionTest.php b/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/EnqueueExtensionTest.php index fdfaac125..014e7c3b5 100644 --- a/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/EnqueueExtensionTest.php +++ b/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/EnqueueExtensionTest.php @@ -546,8 +546,8 @@ public function testShouldConfigureQueueConsumer() 'transport' => [ ], 'consumption' => [ - 'idle-timeout' => 123, - 'receive-timeout' => 456, + 'idle_timeout' => 123, + 'receive_timeout' => 456, ], ]], $container); From 9cbcd83a40cbdb1af96a538cc87acd05a5acda48 Mon Sep 17 00:00:00 2001 From: Alexander Kozienko Date: Fri, 8 Sep 2017 16:56:36 +0300 Subject: [PATCH 09/13] queue consumer options --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e20f62bfe..680d8147f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,7 +49,7 @@ script: - if [ "$PHPSTAN" = true ]; then composer require "phpstan/phpstan:^0.8" ; php -d memory_limit=512M bin/phpstan analyse -l 1 -c phpstan.neon pkg/gps pkg/amqp-ext pkg/async-event-dispatcher pkg/dbal pkg/enqueue pkg/enqueue-bundle pkg/fs pkg/gearman pkg/job-queue pkg/null pkg/pheanstalk pkg/redis pkg/simple-client pkg/sqs pkg/stomp pkg/test pkg/rdkafka; fi - if [ "$PHP_CS_FIXER" = true ]; then IFS=$'\n'; COMMIT_SCA_FILES=($(git diff --name-only --diff-filter=ACMRTUXB "${TRAVIS_COMMIT_RANGE}")); unset IFS; fi - if [ "$PHP_CS_FIXER" = true ]; then ./bin/php-cs-fixer fix --config=.php_cs.dist -v --dry-run --stop-on-violation --using-cache=no --path-mode=intersection -- "${COMMIT_SCA_FILES[@]}"; fi - - if [ "$UNIT_TESTS" = true ]; then bin/phpunit --debug --exclude-group=functional; fi + - if [ "$UNIT_TESTS" = true ]; then bin/phpunit --exclude-group=functional; fi - if [ "$FUNCTIONAL_TESTS" = true ]; then bin/dev -t; fi notifications: From e850510929335b7fa09e724707be3de3ace28f79 Mon Sep 17 00:00:00 2001 From: Alexander Kozienko Date: Fri, 8 Sep 2017 17:31:22 +0300 Subject: [PATCH 10/13] queue consumer options --- .../DependencyInjection/EnqueueExtension.php | 8 ++++---- pkg/enqueue-bundle/Resources/config/client.yml | 2 ++ pkg/enqueue-bundle/Resources/config/services.yml | 2 ++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php b/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php index 42e37ce33..7d1221dcd 100644 --- a/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php +++ b/pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php @@ -112,14 +112,14 @@ public function load(array $configs, ContainerBuilder $container) // configure queue consumer $container->getDefinition('enqueue.consumption.queue_consumer') - ->setArgument(2, $config['consumption']['idle_timeout']) - ->setArgument(3, $config['consumption']['receive_timeout']) + ->replaceArgument(2, $config['consumption']['idle_timeout']) + ->replaceArgument(3, $config['consumption']['receive_timeout']) ; if ($container->hasDefinition('enqueue.client.queue_consumer')) { $container->getDefinition('enqueue.client.queue_consumer') - ->setArgument(2, $config['consumption']['idle_timeout']) - ->setArgument(3, $config['consumption']['receive_timeout']) + ->replaceArgument(2, $config['consumption']['idle_timeout']) + ->replaceArgument(3, $config['consumption']['receive_timeout']) ; } diff --git a/pkg/enqueue-bundle/Resources/config/client.yml b/pkg/enqueue-bundle/Resources/config/client.yml index f7bf69ae8..f8a2b0c83 100644 --- a/pkg/enqueue-bundle/Resources/config/client.yml +++ b/pkg/enqueue-bundle/Resources/config/client.yml @@ -85,6 +85,8 @@ services: arguments: - '@enqueue.transport.context' - '@enqueue.consumption.extensions' + - ~ + - ~ enqueue.client.consume_messages_command: class: 'Enqueue\Symfony\Client\ConsumeMessagesCommand' diff --git a/pkg/enqueue-bundle/Resources/config/services.yml b/pkg/enqueue-bundle/Resources/config/services.yml index 66dc0d1a8..1d13655d7 100644 --- a/pkg/enqueue-bundle/Resources/config/services.yml +++ b/pkg/enqueue-bundle/Resources/config/services.yml @@ -10,6 +10,8 @@ services: arguments: - '@enqueue.transport.context' - '@enqueue.consumption.extensions' + - ~ + - ~ enqueue.command.consume_messages: class: 'Enqueue\Symfony\Consumption\ContainerAwareConsumeMessagesCommand' From 812a069c2de04ea3fb631b9b53ecfcd52e33ce35 Mon Sep 17 00:00:00 2001 From: Alexander Kozienko Date: Mon, 11 Sep 2017 09:24:47 +0300 Subject: [PATCH 11/13] queue consumer options --- .../DependencyInjection/ConfigurationTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/ConfigurationTest.php b/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/ConfigurationTest.php index 8d8ba99cc..81be3a44c 100644 --- a/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/pkg/enqueue-bundle/Tests/Unit/DependencyInjection/ConfigurationTest.php @@ -424,6 +424,23 @@ public function testShouldAllowEnableAsyncEvents() ], $config); } + public function testShouldSetDefaultConfigurationForConsumption() + { + $configuration = new Configuration([]); + + $processor = new Processor(); + $config = $processor->processConfiguration($configuration, [[ + 'transport' => [], + ]]); + + $this->assertArraySubset([ + 'consumption' => [ + 'idle_timeout' => 0, + 'receive_timeout' => 100, + ], + ], $config); + } + public function testShouldAllowConfigureConsumption() { $configuration = new Configuration([]); From 7b3af544f4b2538cf563de5cfa44b883c84f3ce3 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Mon, 11 Sep 2017 12:00:27 +0300 Subject: [PATCH 12/13] upd docs. --- docs/bundle/cli_commands.md | 62 ++++++++++--------- docs/bundle/config_reference.md | 9 +++ .../QueueConsumerOptionsCommandTrait.php | 2 +- 3 files changed, 43 insertions(+), 30 deletions(-) diff --git a/docs/bundle/cli_commands.md b/docs/bundle/cli_commands.md index e6eb497a2..bf1166459 100644 --- a/docs/bundle/cli_commands.md +++ b/docs/bundle/cli_commands.md @@ -20,22 +20,24 @@ Usage: enq:c Arguments: - client-queue-names Queues to consume messages from + client-queue-names Queues to consume messages from Options: - --message-limit=MESSAGE-LIMIT Consume n messages and exit - --time-limit=TIME-LIMIT Consume messages during this time - --memory-limit=MEMORY-LIMIT Consume messages until process reaches this memory limit in MB - --setup-broker Creates queues, topics, exchanges, binding etc on broker side. - -h, --help Display this help message - -q, --quiet Do not output any message - -V, --version Display this application version - --ansi Force ANSI output - --no-ansi Disable ANSI output - -n, --no-interaction Do not ask any interactive question - -e, --env=ENV The environment name [default: "dev"] - --no-debug Switches off debug mode - -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug + --message-limit=MESSAGE-LIMIT Consume n messages and exit + --time-limit=TIME-LIMIT Consume messages during this time + --memory-limit=MEMORY-LIMIT Consume messages until process reaches this memory limit in MB + --setup-broker Creates queues, topics, exchanges, binding etc on broker side. + --idle-timeout=IDLE-TIMEOUT The time in milliseconds queue consumer idle if no message has been received. + --receive-timeout=RECEIVE-TIMEOUT The time in milliseconds queue consumer waits for a message. + -h, --help Display this help message + -q, --quiet Do not output any message + -V, --version Display this application version + --ansi Force ANSI output + --no-ansi Disable ANSI output + -n, --no-interaction Do not ask any interactive question + -e, --env=ENV The environment name [default: "test"] + --no-debug Switches off debug mode + -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Help: A client's worker that processes messages. By default it connects to default queue. It select an appropriate message processor based on a message headers @@ -143,26 +145,28 @@ Help: ``` ./bin/console enqueue:transport:consume --help -Usage: +Usage:ng mqdev_gearmand_1 ... done enqueue:transport:consume [options] [--] Arguments: - processor-service A message processor service + processor-service A message processor service Options: - --message-limit=MESSAGE-LIMIT Consume n messages and exit - --time-limit=TIME-LIMIT Consume messages during this time - --memory-limit=MEMORY-LIMIT Consume messages until process reaches this memory limit in MB - --queue[=QUEUE] Queues to consume from (multiple values allowed) - -h, --help Display this help message - -q, --quiet Do not output any message - -V, --version Display this application version - --ansi Force ANSI output - --no-ansi Disable ANSI output - -n, --no-interaction Do not ask any interactive question - -e, --env=ENV The environment name [default: "dev"] - --no-debug Switches off debug mode - -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug + --message-limit=MESSAGE-LIMIT Consume n messages and exit + --time-limit=TIME-LIMIT Consume messages during this time + --memory-limit=MEMORY-LIMIT Consume messages until process reaches this memory limit in MB + --idle-timeout=IDLE-TIMEOUT The time in milliseconds queue consumer idle if no message has been received. + --receive-timeout=RECEIVE-TIMEOUT The time in milliseconds queue consumer waits for a message. + --queue[=QUEUE] Queues to consume from (multiple values allowed) + -h, --help Display this help message + -q, --quiet Do not output any message + -V, --version Display this application version + --ansi Force ANSI output + --no-ansi Disable ANSI output + -n, --no-interaction Do not ask any interactive question + -e, --env=ENV The environment name [default: "test"] + --no-debug Switches off debug mode + -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Help: A worker that consumes message from a broker. To use this broker you have to explicitly set a queue to consume from and a message processor service diff --git a/docs/bundle/config_reference.md b/docs/bundle/config_reference.md index 6f684ee42..2dd7a888e 100644 --- a/docs/bundle/config_reference.md +++ b/docs/bundle/config_reference.md @@ -298,6 +298,13 @@ enqueue: router_processor: enqueue.client.router_processor default_processor_queue: default redelivered_delay_time: 0 + consumption: + + # the time in milliseconds queue consumer waits if no message received + idle_timeout: 0 + + # the time in milliseconds queue consumer waits for a message (100 ms by default) + receive_timeout: 100 job: false async_events: enabled: false @@ -306,6 +313,8 @@ enqueue: doctrine_clear_identity_map_extension: false signal_extension: true reply_extension: true + + ``` [back to index](../index.md) diff --git a/pkg/enqueue/Symfony/Consumption/QueueConsumerOptionsCommandTrait.php b/pkg/enqueue/Symfony/Consumption/QueueConsumerOptionsCommandTrait.php index 8f1eae00b..c6ffd985f 100644 --- a/pkg/enqueue/Symfony/Consumption/QueueConsumerOptionsCommandTrait.php +++ b/pkg/enqueue/Symfony/Consumption/QueueConsumerOptionsCommandTrait.php @@ -14,7 +14,7 @@ trait QueueConsumerOptionsCommandTrait protected function configureQueueConsumerOptions() { $this - ->addOption('idle-timeout', null, InputOption::VALUE_REQUIRED, 'The time in milliseconds queue consumer waits if no message received.') + ->addOption('idle-timeout', null, InputOption::VALUE_REQUIRED, 'The time in milliseconds queue consumer idle if no message has been received.') ->addOption('receive-timeout', null, InputOption::VALUE_REQUIRED, 'The time in milliseconds queue consumer waits for a message.') ; } From 2b9c6ace55f2d09f8101f47397565b22eefbba95 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Mon, 11 Sep 2017 12:02:00 +0300 Subject: [PATCH 13/13] Release 0.7.11 --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 728aadebf..8d44bdab9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Change Log +## [0.7.11](https://github.com/php-enqueue/enqueue-dev/tree/0.7.11) (2017-09-11) +[Full Changelog](https://github.com/php-enqueue/enqueue-dev/compare/0.7.10...0.7.11) + +- Redis consumer has very high resource usage [\#191](https://github.com/php-enqueue/enqueue-dev/issues/191) + +- Queue Consumer Options [\#193](https://github.com/php-enqueue/enqueue-dev/pull/193) ([ASKozienko](https://github.com/ASKozienko)) +- \[FS\] Polling Interval [\#192](https://github.com/php-enqueue/enqueue-dev/pull/192) ([ASKozienko](https://github.com/ASKozienko)) +- \[Symfony\] added toolbar info in profiler [\#190](https://github.com/php-enqueue/enqueue-dev/pull/190) ([Miliooo](https://github.com/Miliooo)) +- docs cli\_commands.md fix [\#189](https://github.com/php-enqueue/enqueue-dev/pull/189) ([Miliooo](https://github.com/Miliooo)) + ## [0.7.10](https://github.com/php-enqueue/enqueue-dev/tree/0.7.10) (2017-08-31) [Full Changelog](https://github.com/php-enqueue/enqueue-dev/compare/0.7.9...0.7.10)