码迷,mamicode.com
首页 > 编程语言 > 详细

python rabbit MQ

时间:2017-11-05 10:51:20      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:receive   bit   eth   print   ram   imp   block   connect   close   

produce:

import pika
connection = pika.BlockingConnection(pika.ConnectionParameters("localhost") )
channel=connection.channel()
channel.queue_declare(queue="hello")
channel.basic_publish(exchange=‘‘,routing_key="hello",body="Hello World")
print("sent ‘hello world")
connection.close()

consumer:
import pika
connection=pika.BlockingConnection (pika.ConnectionParameters("localhost"))
channel=connection.channel()
channel.queue_declare(queue="hello")
def callback(ch,method,properties,body):
# print(ch)
# print(method)
# print(properties)
print("Received %r"%body)
channel.basic_consume(callback,queue=‘hello‘,no_ack=True)
print("wait ....")
channel.start_consuming()

python rabbit MQ

标签:receive   bit   eth   print   ram   imp   block   connect   close   

原文地址:http://www.cnblogs.com/xiesongyou/p/7786786.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!