上一章节我们讲述了php的rabbitmq的持久化。这次我们讨论php的rabbitmq消费
$ename = "ename15";
$qname = "queue15";
$con = new AMQPConnection();
$con->connect();
$ch = new AMQPChannel($con);
$q = new AMQPQueue($ch);
$q->setName($qname);
$q->setFlags(2);
$q->declare();
$ex = new AMQPExchange($ch);
$ex->setName($ename);
$ex->setType(AMQP_EX_TYPE_DIRECT);
$ex->setFlags(2);
$ex->declare();
$q->bind($ename,$qname);
$message = $q->get(AMQP_AUTOACK);
if ( $message == false ) {
printf("no messages in queue $queueName");
}
else{
echo $message->getBody(); // print Hello World!
}
$ename = "ename15";
$qname = "queue15";
$con = new AMQPConnection();
$con->connect();
$ch = new AMQPChannel($con);
$q = new AMQPQueue($ch);
$q->setName($qname);
$q->setFlags(2);
$q->declare();
$ex = new AMQPExchange($ch);
$ex->setName($ename);
$ex->setType(AMQP_EX_TYPE_DIRECT);
$ex->setFlags(2);
$ex->declare();
$q->bind($ename,$qname);
$message = $q->get(AMQP_AUTOACK);
if ( $message == false ) {
printf("no messages in queue $queueName");
}
else{
echo $message->getBody(); // print Hello World!
}