RabbitMQ consumers do not process messages in the queue after a period of time(PHP ext: php-amqp).

34 views
Skip to first unread message

U2B

unread,
Dec 5, 2023, 8:30:01 PM12/5/23
to rabbitmq-users
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_keyAMQP_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());
    });
}

Adam Szczepanski

unread,
Dec 6, 2023, 1:34:54 AM12/6/23
to rabbitmq-users
did you try with another client to consume the message ? Because it does not seems to be related to RabbitMQ server, more on the client side...
Or/and do you see the request coming in in RabbitMQ server ? I mean metrics changing when you get the consume request by example.
Eventually, catch the exception in your PHP code, to see if anything special is happening.

Reply all
Reply to author
Forward
0 new messages