标签:
RabbitMQ使用AMQP通信协议(AMQP是一个提供统一消息服务的应用层标准协议,基于此协议的客户端与消息中间件可传递消息,并不受客户端/中间件不同产品,不同开发语言等条件的限制。)。
sudo pip install pika==0.9.8
sudo apt-get install rabbitmq-server
rabbitmq-server start
#!/usr/bin/env python # coding=utf-8 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()
#!/usr/bin/env python # coding=utf-8 import pika def callback(ch, method, properties, body): print ‘receive %r‘%body connection = pika.BlockingConnection(pika.ConnectionParameters(‘localhost‘)) channel = connection.channel() channel.queue_declare(queue=‘hello‘) channel.basic_consume(callback, queue=‘hello‘, no_ack=True) channel.start_consuming()
标签:
原文地址:http://www.cnblogs.com/coder2012/p/4338367.html