Page 79 - Python rat la co ban
P. 79

Ở bước trước, ta đã tạo một message lên queue. Ở bước


          này, ta sẽ khai báo một worker xử lý các message nhận


          được từ channel  hello .





           import pika




           connection = pika.BlockingConnection(pika.Connectio

           nParameters(host='localhost'))

           channel = connection.channel()



           channel.queue_declare(queue='hello')



           print ' [*] Waiting for messages. To exit press CTR

           L+C'



           def callback(ch, method, properties, body):

               print " [x] Received %r" % (body,)



           channel.basic_consume(callback, queue='hello', no_a

           ck=True)



           channel.start_consuming()






          Đoạn code này cũng có phần khai báo  connection ,
   74   75   76   77   78   79   80   81   82   83   84