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(); }