From 99be00e990c5fee5376be890f735c8c92a17613d Mon Sep 17 00:00:00 2001 From: Alexandru Bumbacea Date: Wed, 31 Aug 2016 21:00:02 +0300 Subject: [PATCH] Ability to restart consumer from within "execute" by throwing \OldSound\RabbitMqBundle\RabbitMq\Exception\StopConsumerException --- RabbitMq/Consumer.php | 9 +++++++++ RabbitMq/Exception/StopConsumerException.php | 15 +++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 RabbitMq/Exception/StopConsumerException.php diff --git a/RabbitMq/Consumer.php b/RabbitMq/Consumer.php index d565aaa5..0d074707 100644 --- a/RabbitMq/Consumer.php +++ b/RabbitMq/Consumer.php @@ -90,6 +90,15 @@ public function processMessage(AMQPMessage $msg) 'return_code' => $processFlag ) )); + } catch (Exception\StopConsumerException $e) { + $this->logger->info('Consumer requested restart', array( + 'amqp' => array( + 'queue' => $this->queueOptions['name'], + 'message' => $msg, + 'stacktrace' => $e->getTraceAsString() + ) + )); + $this->stopConsuming(); } catch (\Exception $e) { $this->logger->error($e->getMessage(), array( 'amqp' => array( diff --git a/RabbitMq/Exception/StopConsumerException.php b/RabbitMq/Exception/StopConsumerException.php new file mode 100644 index 00000000..f7edd37d --- /dev/null +++ b/RabbitMq/Exception/StopConsumerException.php @@ -0,0 +1,15 @@ +