diff --git a/CHANGELOG.md b/CHANGELOG.md index cc4f53ec6..243408045 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Change Log +## [0.9.11](https://github.com/php-enqueue/enqueue-dev/tree/0.9.11) (2019-05-24) +[Full Changelog](https://github.com/php-enqueue/enqueue-dev/compare/0.9.10...0.9.11) + +**Merged pull requests:** + +- \[client\] Fix --logger option. Removed unintentionally set console logger. [\#861](https://github.com/php-enqueue/enqueue-dev/pull/861) ([makasim](https://github.com/makasim)) +- \[client\] Fix reference to logger service. [\#860](https://github.com/php-enqueue/enqueue-dev/pull/860) ([makasim](https://github.com/makasim)) +- \[consumption\] Fix bindCallback method will require new arg deprecation notice [\#859](https://github.com/php-enqueue/enqueue-dev/pull/859) ([makasim](https://github.com/makasim)) +- \[amqp-bunny\] Revert "Fix heartbeat configuration in bunny with 0 \(off\) value" [\#855](https://github.com/php-enqueue/enqueue-dev/pull/855) ([DamienHarper](https://github.com/DamienHarper)) +- \[sqs\] Requeue with a visibility timeout [\#852](https://github.com/php-enqueue/enqueue-dev/pull/852) ([deguif](https://github.com/deguif)) +- \[monitoring\] Send topic and command for consumed messages [\#849](https://github.com/php-enqueue/enqueue-dev/pull/849) ([mariusbalcytis](https://github.com/mariusbalcytis)) +- Fixed typo [\#856](https://github.com/php-enqueue/enqueue-dev/pull/856) ([samnela](https://github.com/samnela)) + ## [0.9.10](https://github.com/php-enqueue/enqueue-dev/tree/0.9.10) (2019-05-14) [Full Changelog](https://github.com/php-enqueue/enqueue-dev/compare/0.9.9...0.9.10) diff --git a/docs/monolog/send-messages-to-mq.md b/docs/monolog/send-messages-to-mq.md index c6cac342c..bbfea16ab 100644 --- a/docs/monolog/send-messages-to-mq.md +++ b/docs/monolog/send-messages-to-mq.md @@ -18,7 +18,7 @@ You have to install monolog itself, queue interop handlers and one of [the trans For the simplicity we are going to install the filesystem based MQ. ``` -composer require enqueue/monolog-queue-handler monolog/monlog enqueue/fs +composer require enqueue/monolog-queue-handler monolog/monolog enqueue/fs ``` ## Usage @@ -66,4 +66,4 @@ $consumer->consume(); ``` -[back to index](../index.md) \ No newline at end of file +[back to index](../index.md) diff --git a/pkg/amqp-bunny/AmqpConnectionFactory.php b/pkg/amqp-bunny/AmqpConnectionFactory.php index ca56d428c..241929abe 100644 --- a/pkg/amqp-bunny/AmqpConnectionFactory.php +++ b/pkg/amqp-bunny/AmqpConnectionFactory.php @@ -87,7 +87,6 @@ private function establishConnection(): BunnyClient $bunnyConfig['password'] = $this->config->getPass(); $bunnyConfig['read_write_timeout'] = min($this->config->getReadTimeout(), $this->config->getWriteTimeout()); $bunnyConfig['timeout'] = $this->config->getConnectionTimeout(); - $bunnyConfig['heartbeat'] = $this->config->getHeartbeat(); // @see https://github.com/php-enqueue/enqueue-dev/issues/229 // $bunnyConfig['persistent'] = $this->config->isPersisted(); @@ -95,6 +94,10 @@ private function establishConnection(): BunnyClient // $bunnyConfig['path'] = 'enqueue';//$this->config->getOption('path', $this->config->getOption('vhost')); // } + if ($this->config->getHeartbeat()) { + $bunnyConfig['heartbeat'] = $this->config->getHeartbeat(); + } + if (null !== $this->config->getOption('tcp_nodelay')) { $bunnyConfig['tcp_nodelay'] = $this->config->getOption('tcp_nodelay'); } diff --git a/pkg/enqueue/Consumption/QueueConsumerInterface.php b/pkg/enqueue/Consumption/QueueConsumerInterface.php index c9c99ef15..430aa8786 100644 --- a/pkg/enqueue/Consumption/QueueConsumerInterface.php +++ b/pkg/enqueue/Consumption/QueueConsumerInterface.php @@ -27,9 +27,8 @@ public function bind($queueName, Processor $processor): self; /** * @param string|InteropQueue $queueName - * @param mixed $queue */ - public function bindCallback($queue, callable $processor): self; + public function bindCallback($queueName, callable $processor): self; /** * Runtime extension - is an extension or a collection of extensions which could be set on runtime. diff --git a/pkg/enqueue/Symfony/Client/ConsumeCommand.php b/pkg/enqueue/Symfony/Client/ConsumeCommand.php index ee8b394f6..fee54e1b5 100644 --- a/pkg/enqueue/Symfony/Client/ConsumeCommand.php +++ b/pkg/enqueue/Symfony/Client/ConsumeCommand.php @@ -5,7 +5,6 @@ use Enqueue\Client\DriverInterface; use Enqueue\Consumption\ChainExtension; use Enqueue\Consumption\Extension\ExitStatusExtension; -use Enqueue\Consumption\Extension\LoggerExtension; use Enqueue\Consumption\ExtensionInterface; use Enqueue\Consumption\QueueConsumerInterface; use Enqueue\Symfony\Consumption\ChooseLoggerCommandTrait; @@ -18,7 +17,6 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Logger\ConsoleLogger; use Symfony\Component\Console\Output\OutputInterface; class ConsumeCommand extends Command @@ -154,7 +152,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int protected function getRuntimeExtensions(InputInterface $input, OutputInterface $output): ExtensionInterface { - $extensions = [new LoggerExtension(new ConsoleLogger($output))]; + $extensions = []; $extensions = array_merge($extensions, $this->getLimitsExtensions($input, $output)); $driver = $this->getDriver($input->getOption('client')); diff --git a/pkg/enqueue/Symfony/Client/DependencyInjection/ClientFactory.php b/pkg/enqueue/Symfony/Client/DependencyInjection/ClientFactory.php index bdae6f3b5..2eede31b7 100644 --- a/pkg/enqueue/Symfony/Client/DependencyInjection/ClientFactory.php +++ b/pkg/enqueue/Symfony/Client/DependencyInjection/ClientFactory.php @@ -165,7 +165,7 @@ public function build(ContainerBuilder $container, array $config): void ->addArgument($this->diUtils->reference('context')) ->addArgument($this->diUtils->reference('consumption_extensions')) ->addArgument([]) - ->addArgument($this->diUtils->reference('logger', ContainerInterface::NULL_ON_INVALID_REFERENCE)) + ->addArgument(new Reference('logger', ContainerInterface::NULL_ON_INVALID_REFERENCE)) ->addArgument($config['consumption']['receive_timeout']) ; diff --git a/pkg/monitoring/InfluxDbStorage.php b/pkg/monitoring/InfluxDbStorage.php index 401d79ddb..ff5f6c3b0 100644 --- a/pkg/monitoring/InfluxDbStorage.php +++ b/pkg/monitoring/InfluxDbStorage.php @@ -160,6 +160,16 @@ public function pushConsumedMessageStats(ConsumedMessageStats $stats): void 'status' => $stats->getStatus(), ]; + $properties = $stats->getProperties(); + + if (false === empty($properties[Config::TOPIC])) { + $tags['topic'] = $properties[Config::TOPIC]; + } + + if (false === empty($properties[Config::COMMAND])) { + $tags['command'] = $properties[Config::COMMAND]; + } + $values = [ 'receivedAt' => $stats->getReceivedAtMs(), 'processedAt' => $stats->getTimestampMs(), diff --git a/pkg/sqs/SqsConsumer.php b/pkg/sqs/SqsConsumer.php index 3c8714e3d..4b89eb7ff 100644 --- a/pkg/sqs/SqsConsumer.php +++ b/pkg/sqs/SqsConsumer.php @@ -138,7 +138,7 @@ public function reject(Message $message, bool $requeue = false): void '@region' => $this->queue->getRegion(), 'QueueUrl' => $this->context->getQueueUrl($this->queue), 'ReceiptHandle' => $message->getReceiptHandle(), - 'VisibilityTimeout' => 0, + 'VisibilityTimeout' => $message->getRequeueVisibilityTimeout(), ]); } else { $this->context->getSqsClient()->deleteMessage([ diff --git a/pkg/sqs/SqsMessage.php b/pkg/sqs/SqsMessage.php index 1d9d26bec..3b0f46bd9 100644 --- a/pkg/sqs/SqsMessage.php +++ b/pkg/sqs/SqsMessage.php @@ -48,6 +48,11 @@ class SqsMessage implements Message */ private $receiptHandle; + /** + * @var int + */ + private $requeueVisibilityTimeout; + public function __construct(string $body = '', array $properties = [], array $headers = []) { $this->body = $body; @@ -55,6 +60,7 @@ public function __construct(string $body = '', array $properties = [], array $he $this->headers = $headers; $this->redelivered = false; $this->delaySeconds = 0; + $this->requeueVisibilityTimeout = 0; } public function setBody(string $body): void @@ -229,4 +235,19 @@ public function getReceiptHandle(): ?string { return $this->receiptHandle; } + + /** + * The number of seconds before the message can be visible again when requeuing. Valid values: 0 to 43200. Maximum: 12 hours. + * + * Set requeue visibility timeout + */ + public function setRequeueVisibilityTimeout(int $seconds): void + { + $this->requeueVisibilityTimeout = $seconds; + } + + public function getRequeueVisibilityTimeout(): int + { + return $this->requeueVisibilityTimeout; + } } diff --git a/pkg/sqs/Tests/SqsConsumerTest.php b/pkg/sqs/Tests/SqsConsumerTest.php index 67e6f8fc4..ea5c557b5 100644 --- a/pkg/sqs/Tests/SqsConsumerTest.php +++ b/pkg/sqs/Tests/SqsConsumerTest.php @@ -238,6 +238,47 @@ public function testShouldRejectMessageAndRequeue() $consumer->reject($message, true); } + public function testShouldRejectMessageAndRequeueWithVisibilityTimeout() + { + $client = $this->createSqsClientMock(); + $client + ->expects($this->once()) + ->method('changeMessageVisibility') + ->with($this->identicalTo([ + '@region' => 'theRegion', + 'QueueUrl' => 'theQueueUrl', + 'ReceiptHandle' => 'theReceipt', + 'VisibilityTimeout' => 30, + ])) + ; + + $context = $this->createContextMock(); + $context + ->expects($this->once()) + ->method('getSqsClient') + ->willReturn($client) + ; + $context + ->expects($this->once()) + ->method('getQueueUrl') + ->willReturn('theQueueUrl') + ; + $context + ->expects($this->never()) + ->method('createProducer') + ; + + $message = new SqsMessage(); + $message->setReceiptHandle('theReceipt'); + $message->setRequeueVisibilityTimeout(30); + + $destination = new SqsDestination('queue'); + $destination->setRegion('theRegion'); + + $consumer = new SqsConsumer($context, $destination); + $consumer->reject($message, true); + } + public function testShouldReceiveMessage() { $expectedAttributes = [