Created
November 22, 2013 05:20
-
-
Save ygmpkk/7595230 to your computer and use it in GitHub Desktop.
RABBIRMQ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#连接rabbitmq服务器 | |
connection = pika.BlockingConnection(pika.ConnectionParameters( | |
host='host')) | |
channel = connection.channel() | |
#定义队列 | |
channel.queue_declare(queue='test_queue') | |
channel.queue_bind(exchange='test_exchange', | |
queue='test_queue', | |
routing_key='test_route_key') | |
channel.queue_declare(queue='test_server_queue') | |
channel.queue_bind(exchange='test_server_exchange', | |
queue='test_server_queue', | |
routing_key='test_server_route_key') | |
print ' [*] Waiting for n' | |
#定义接收到消息的处理方法 | |
def request(ch, method, properties, body): | |
print " [.] increase(%s)" % (body,) | |
m = json.loads(body) | |
response = increase(m, ch, method) | |
#if m.get ('C') == 14 and m.get('O') == 'C': | |
# t = threading.Thread(target=readbook, args=(ch, method)) | |
# t.start() | |
# t.join() | |
print response | |
channel.basic_qos(prefetch_count=1) | |
channel.basic_consume(request, queue='elizur_queue') | |
channel.start_consuming() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment