Skip to content

Instantly share code, notes, and snippets.

@ygmpkk
Created November 22, 2013 05:20
Show Gist options
  • Save ygmpkk/7595230 to your computer and use it in GitHub Desktop.
Save ygmpkk/7595230 to your computer and use it in GitHub Desktop.
RABBIRMQ
#连接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