Skip to content

Commit 3e21185

Browse files
committed
Fixed handling of system signals when waiting for a new message from the queue. Close #178
1 parent 3dd7076 commit 3e21185

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Command/BaseConsumerCommand.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace OldSound\RabbitMqBundle\Command;
44

55
use OldSound\RabbitMqBundle\RabbitMq\BaseConsumer as Consumer;
6+
use PhpAmqpLib\Exception\AMQPTimeoutException;
67
use Symfony\Component\Console\Input\InputArgument;
78
use Symfony\Component\Console\Input\InputInterface;
89
use Symfony\Component\Console\Input\InputOption;
@@ -19,7 +20,13 @@ abstract protected function getConsumerService();
1920
public function stopConsumer()
2021
{
2122
if ($this->consumer instanceof Consumer) {
23+
// Process current message, then halt consumer
2224
$this->consumer->forceStopConsumer();
25+
26+
// Halt consumer if waiting for a new message from the queue
27+
try {
28+
$this->consumer->stopConsuming();
29+
} catch (AMQPTimeoutException $e) {}
2330
} else {
2431
exit();
2532
}

0 commit comments

Comments
 (0)