diff --git a/src/VladimirYuldashev/LaravelQueueRabbitMQ/Queue/RabbitMQQueue.php b/src/VladimirYuldashev/LaravelQueueRabbitMQ/Queue/RabbitMQQueue.php index 6f13eea1..3bd29dd2 100644 --- a/src/VladimirYuldashev/LaravelQueueRabbitMQ/Queue/RabbitMQQueue.php +++ b/src/VladimirYuldashev/LaravelQueueRabbitMQ/Queue/RabbitMQQueue.php @@ -324,10 +324,17 @@ public function getCorrelationId() /** * @param string $action * @param Exception $e + * @throws Exception */ protected function reportConnectionError($action, Exception $e) { Log::error('AMQP error while attempting '.$action.': '.$e->getMessage()); + + // If it's set to false, throw an error rather than waiting + if ($this->sleepOnError === false) { + throw new \RuntimeException('Error writing data to the connection with RabbitMQ'); + } + // Sleep so that we don't flood the log file sleep($this->sleepOnError); } diff --git a/src/config/rabbitmq.php b/src/config/rabbitmq.php index fa428c32..c1390956 100644 --- a/src/config/rabbitmq.php +++ b/src/config/rabbitmq.php @@ -40,6 +40,8 @@ 'auto_delete' => env('RABBITMQ_EXCHANGE_AUTODELETE', false), ], - 'sleep_on_error' => env('RABBITMQ_ERROR_SLEEP', 5), // the number of seconds to sleep if there's an error communicating with rabbitmq + // the number of seconds to sleep if there's an error communicating with rabbitmq + // if set to false, it'll throw an exception rather than doing the sleep for X seconds + 'sleep_on_error' => env('RABBITMQ_ERROR_SLEEP', 5), ];