I need to create a simple queue manager to pass the number from the sender to the consumer. The Hello World tutorial provided by RabbitMQ covers nearly 70% of it.
But I need to change the queue so as not to forever wait for incoming messages. Or stop after a certain number of messages. I read and tried several solutions from another post, but it does not work.
rabbitmq AMQP :: consumume () is an undefined method. there is another method, wait_frame, but it is protected.
and another post is in python which I don't understand.
<?php require_once __DIR__ . '/vendor/autoload.php'; require 'config.php'; use PhpAmqpLib\Connection\AMQPStreamConnection; function recieveQueue($queueName){ $connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest'); // try{ // $connection->wait_frame(10); // }catch(AMQPConnectionException $e){ // echo "asdasd"; // } $channel = $connection->channel(); $channel->queue_declare($queueName, false, false, false, false); echo ' [*] Waiting for messages. To exit press CTRL+C', "\n"; $callback = function($msg) { echo " [x] Received ", $msg->body, "\n"; }; // $tag = uniqid() . microtime(true); // $queue->consume($callback, $flags, $tag); $channel->basic_consume($queueName, '', false, true, false, false, $callback); // $channel->cancel($tag); while(count($channel->callbacks)) { $channel->wait(); } echo "\nfinish"; } recieveQueue('vtiger'); ?>
php wait rabbitmq amqp php-amqplib
jedi
source share