From 3e211851d25a9670ed0a3e175a0ba217e4708ab0 Mon Sep 17 00:00:00 2001 From: Antonio Trapani Date: Thu, 11 Dec 2014 13:29:20 +0100 Subject: [PATCH] Fixed handling of system signals when waiting for a new message from the queue. Close #178 --- Command/BaseConsumerCommand.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Command/BaseConsumerCommand.php b/Command/BaseConsumerCommand.php index 241a26b1..caf90d43 100644 --- a/Command/BaseConsumerCommand.php +++ b/Command/BaseConsumerCommand.php @@ -3,6 +3,7 @@ namespace OldSound\RabbitMqBundle\Command; use OldSound\RabbitMqBundle\RabbitMq\BaseConsumer as Consumer; +use PhpAmqpLib\Exception\AMQPTimeoutException; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -19,7 +20,13 @@ abstract protected function getConsumerService(); public function stopConsumer() { if ($this->consumer instanceof Consumer) { + // Process current message, then halt consumer $this->consumer->forceStopConsumer(); + + // Halt consumer if waiting for a new message from the queue + try { + $this->consumer->stopConsuming(); + } catch (AMQPTimeoutException $e) {} } else { exit(); }