Skip to content

Commit 7c7ac39

Browse files
authored
Exception thrown by ::pop is checked by Illuminate\Database\DetectsLostConnections::causedByLostConnection (#457)
It should throw exception with special message in order to end queue on error correctly. Otherwise, it continues to work with broken connection.
1 parent 586d230 commit 7c7ac39

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Queue/RabbitMQQueue.php

+13
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
use JsonException;
1414
use PhpAmqpLib\Channel\AMQPChannel;
1515
use PhpAmqpLib\Connection\AbstractConnection;
16+
use PhpAmqpLib\Exception\AMQPChannelClosedException;
17+
use PhpAmqpLib\Exception\AMQPConnectionClosedException;
1618
use PhpAmqpLib\Exception\AMQPProtocolChannelException;
19+
use PhpAmqpLib\Exception\AMQPRuntimeException;
1720
use PhpAmqpLib\Exchange\AMQPExchangeType;
1821
use PhpAmqpLib\Message\AMQPMessage;
1922
use PhpAmqpLib\Wire\AMQPTable;
@@ -254,6 +257,16 @@ public function pop($queue = null)
254257
}
255258

256259
throw $exception;
260+
} catch (AMQPChannelClosedException|AMQPConnectionClosedException $exception) {
261+
// Queue::pop used by worker to receive new job
262+
// Thrown exception is checked by Illuminate\Database\DetectsLostConnections::causedByLostConnection
263+
// Is has to contain one of the several phrases in exception message in order to restart worker
264+
// Otherwise worker continues to work with broken connection
265+
throw new AMQPRuntimeException(
266+
'Lost connection: '.$exception->getMessage(),
267+
$exception->getCode(),
268+
$exception
269+
);
257270
}
258271

259272
return null;

0 commit comments

Comments
 (0)