#/usr/bin/env python
# -*- conding:utf8 -*-
import pika
import traceback
try:
connection = pika.BlockingConnection(pika.ConnectionParameters('192.168.4.226'))
channel = connection.channel()
print dir(channel)
except Exception,e:
print e
def rabbitmq_receive():
try:
channel.queue_declare(queue='abcde')
print "[x] Warting for messages. to exit press CRTCL + C"
except:
print traceback.print_exc()
def callback(ch,method,properties,body):
print ' [x] Received %r' %(body,)
def main():
rabbitmq_receive()
try:
channel.basic_consume(callback,
queue='abcde',
no_ack=True)
channel.start_consuming()
except:
print traceback.print_exc()
if __name__ == "__main__":
sv = main()
# -*- conding:utf8 -*-
import pika
import traceback
try:
connection = pika.BlockingConnection(pika.ConnectionParameters('192.168.4.226'))
channel = connection.channel()
print dir(channel)
except Exception,e:
print e
def rabbitmq_receive():
try:
channel.queue_declare(queue='abcde')
print "[x] Warting for messages. to exit press CRTCL + C"
except:
print traceback.print_exc()
def callback(ch,method,properties,body):
print ' [x] Received %r' %(body,)
def main():
rabbitmq_receive()
try:
channel.basic_consume(callback,
queue='abcde',
no_ack=True)
channel.start_consuming()
except:
print traceback.print_exc()
if __name__ == "__main__":
sv = main()
本文转自 swq499809608 51CTO博客,原文链接:http://blog.51cto.com/swq499809608/1230179