Skip to content

Commit 911770d

Browse files
authored
Merge pull request vyuldashev#125 from werewolf81/master
Fix for lost connections with RabbitMQ
2 parents 4443ea5 + a2db1e6 commit 911770d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/VladimirYuldashev/LaravelQueueRabbitMQ/Queue/RabbitMQQueue.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,17 @@ public function getCorrelationId()
324324
/**
325325
* @param string $action
326326
* @param Exception $e
327+
* @throws Exception
327328
*/
328329
protected function reportConnectionError($action, Exception $e)
329330
{
330331
Log::error('AMQP error while attempting '.$action.': '.$e->getMessage());
332+
333+
// If it's set to false, throw an error rather than waiting
334+
if ($this->sleepOnError === false) {
335+
throw new \RuntimeException('Error writing data to the connection with RabbitMQ');
336+
}
337+
331338
// Sleep so that we don't flood the log file
332339
sleep($this->sleepOnError);
333340
}

src/config/rabbitmq.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
'auto_delete' => env('RABBITMQ_EXCHANGE_AUTODELETE', false),
4141
],
4242

43-
'sleep_on_error' => env('RABBITMQ_ERROR_SLEEP', 5), // the number of seconds to sleep if there's an error communicating with rabbitmq
43+
// the number of seconds to sleep if there's an error communicating with rabbitmq
44+
// if set to false, it'll throw an exception rather than doing the sleep for X seconds
45+
'sleep_on_error' => env('RABBITMQ_ERROR_SLEEP', 5),
4446

4547
];

0 commit comments

Comments
 (0)