装了amqp 1.0.1 PHP的extension...
看着在线文档..写了个程序可以发送消息去消息队列...
但是接收不会写...因为PHP在线关于AMQP的文档范例是错的...
比如AMQPQueue的declare(void)..
但是范例却写declare("xxxx")...
求PHP的amqp 1.0.1 的正常范例....
help me ...thx...
@红薯
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
$q->get(AMQP_AUTOACK); 请教关于这个的问题 如果我是这么写 $q->get(); 队列中的数据如何清楚 ######<?php
//设置你的连接
$conn_args = array('host' => 'localhost', 'port' => '5672', 'login' => 'guest', 'password' => 'guest');
$conn = new AMQPConnection($conn_args);
if ($conn->connect()) {
echo "Established a connection to the broker \n";
}
else {
echo "Cannot connect to the broker \n ";
}
//你的消息
$message = json_encode(array('Hello World!','php','c++'));
//创建channel
$channel = new AMQPChannel($conn);
//创建exchange
$ex = new AMQPExchange($channel);
$ex->setName('exchange');//创建名字
$ex->setType(AMQP_EX_TYPE_DIRECT);
$ex->setFlags(AMQP_DURABLE | AMQP_AUTODELETE);
echo "exchange status:".$ex->declare();
echo "\n";
//创建队列
$q = new AMQPQueue($channel);
//设置队列名字 如果不存在则添加
$q->setName('queue');
$q->setFlags(AMQP_DURABLE | AMQP_AUTODELETE);
echo "queue status: ".$q->declare();
echo "\n";
echo 'queue bind: '.$q->bind('exchange','route.key');//将你的队列绑定到routingKey
echo "\n";
$channel->startTransaction();
echo "send: ".$ex->publish($message, 'route.key'); //将你的消息通过制定routingKey发送
$channel->commitTransaction();
$conn->disconnect();
?>######
我知道publish没问题。。。我要get啊。。。。
$conn_args = array('host' => '192.168.4.1', 'port' => '5672', 'login' => 'test', 'password' => 'test' ,'vhost'=>'localhost'); $cnn = new AMQPConnection($conn_args); $cnn->connect(); $ch = new AMQPChannel($cnn); // Declare a new exchange $ex = new AMQPExchange($ch); $ex->setName('exchange1'); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declare(); // Create a new queue $q = new AMQPQueue($ch); $q->setName('queue1' . time()); $q->declare(); // Bind it on the exchange to routing.key $q->bind($ex->getName(), 'routing.*'); // Publish a message to the exchange with a routing key $ex->publish('message', 'routing.1'); $ex->publish('message2', 'routing.2'); $ex->publish('message3', 'routing.3'); for ($i = 0; $i < 3; $i++) { // Read from the queue $msg = $q->get(AMQP_AUTOACK); echo $msg->getBody() . "\n"; } $ex->delete();