Producer loop execution, consumer start in CLI mode, consumer can receive message at the beginning of startup, but consumer cannot receive message after a period of time (about 1000 seconds). The consumer did not report an error or stop running,How can I solve this problem?
producer
<?php
$connect = new \AMQPConnection([
"host" => '192.168.1.111',
"port" => 5672,
"login" => 'user',
"password" => 'pswd',
"vhost" => '/',
]);
$connect->connect();
$channel = new \AMQPChannel($connect);
$exchange_name = "exchange.a";
$exchange = new \AMQPExchange($channel);
$exchange->setName($exchange_name);
$exchange->setFlags(AMQP_DURABLE);
$exchange->setType(AMQP_EX_TYPE_DIRECT);
$exchange->declareExchange();
$queue_name = "queue.a";
$queue = new \AMQPQueue($channel);
$queue->setName($queue_name);
$queue->setFlags(AMQP_DURABLE);
$queue->declareQueue();
$binding_key = "route.a";
$arguments = [];
$queue->bind($exchange_name, $binding_key, $arguments);
$message = 'Hello world!';
$routing_key = "route.a";
$attributes = [
'delivery_mode' => AMQP_DURABLE,
];
$exchange->publish($message, $routing_key, AMQP_NOPARAM, $attributes);$connect->disconnect();
consumer
<?php
$connect = new \AMQPConnection([
"host" => '192.168.1.111',
"port" => '5672',
"login" => 'user',
"password" => 'pswd',
"vhost" => '/',
]);
$connect->connect();
$channel = new \AMQPChannel($connect);
$queue_name = "queue.a";
$queue = new \AMQPQueue($channel);
$queue->setName($queue_name);
$queue->setFlags(AMQP_DURABLE);
$queue->declareQueue();
while (true) {
$queue->consume(function ($envelope, $queue) {
$message = $envelope->getBody();
echo "{$message}\n";
$queue->ack($envelope->getDeliveryTag());
});
}