I have a php daemon, which uses php-amqplib, that consumes messages from RabbitMQ server. Here is a gist of it (though it's a bit more complex than that):
$callback = function (AMQPMessage $msg) {
echo "Handling event: some event name here";
try {
//some custom logic here
} catch (\Throwable $e) {
//write error in a log here
}
$msg->ack();
};
$channel = $this->connection->channel();
$channel->basic_qos(null, 1, null);
$channel->basic_consume($queue, '', false, false, false, false, $callback);
$this->wait($channel);
while ($channel->is_open()) {
$channel->wait();
}
$channel->close();
$this->connection->close();
When I run it in the background, it handles the events, writes output and errors to various logs and I can see in RabbitMQ control panel that the queue has consumers. Then after quite some time it just stops doing that: there are no messages appearing in both error and output logs, the RabbitMQ control panel shows that the queue has 0 consumers, but the process is still running somehow.