Python队列RabbitMQ使用方法实例记录-创新互联
本文实例讲述了Python队列RabbitMQ 使用方法。分享给大家供大家参考,具体如下:
创新互联建站主营屯昌网站建设的网络公司,主营网站建设方案,重庆APP开发,屯昌h5小程序开发搭建,屯昌网站营销推广欢迎屯昌等地区企业咨询目前的exchange的路由策略是:每个需要队列的服务独享一个队列(queue),消费者(consumer)采用ACK自动应答模式处理队列消息。
如果需要新增一个队列服务,需要做如下开发步骤:
1.创建队列,发送消息
<?php $routingkey = 'key'; //设置你的连接 $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 World3!', 'php3', 'c++3:')); //创建channel $channel = new AMQPChannel($conn); //创建exchange $ex = new AMQPExchange($channel); $ex->setName('exchange2'); //创建名字 $ex->setType(AMQP_EX_TYPE_DIRECT); $ex->setFlags(AMQP_DURABLE); echo "exchange2 status:" . $ex->declareExchange(); echo "\n"; for ($i = 0; $i < 100; $i++) { if ($routingkey == 'key2') { $routingkey = 'key'; } else { $routingkey = 'key2'; } $ex->publish($message, $routingkey); }
网站题目:Python队列RabbitMQ使用方法实例记录-创新互联
当前网址:http://myzitong.com/article/cddsjg.html