I am trying to use php-amqplib to send and receive a message. It works by sending / receiving to the terminal. But when you switch to a web browser, you cannot receive from the queue, it is constantly waiting for a message. I used below code to get .php
require_once(__DIR__ . '/lib/php-amqplib/amqp.inc'); include_once(__DIR__ . '/config/config.php'); $connection = new AMQPConnection(HOST, PORT, USER, PASS, VHOST); $channel = $connection->channel(); $channel->queue_declare('test22'); $callback = function($msg){ echo $msg->body; }; $channel->basic_consume('test22', 'consumer_tag', false, true, false, false, $callback); while(count($channel->callbacks)) { $channel->wait(); } $channel->close(); $connection->close();
It receives the first message from the queue if I use below instead of the callback function, but does not consume from the queue
$abc=$channel->basic_get("test22", false, 2); if(!empty($abc)) { print_r($abc->body); }
This means that messages are available in the queue 'test22'. give me any hint.
source share