pika 消费者模型
# -*- coding: utf-8 -*-# by dl# !/usr/bin/env python# coding=utf8import pikaconnection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))channel = connection.channel()cha...
·
# -*- coding: utf-8 -*-
# by dl
# !/usr/bin/env python
# coding=utf8
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(
'localhost'))
channel = connection.channel()
channel.queue_declare(queue='helloDL')
def callback(ch, method, properties, body):
print(" [x] Received %r" % (body,))
# channel.basic_consume(callback, queue='hello', no_ack=True)
channel.basic_consume('helloDL', callback, consumer_tag="hello-consumer")
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
>>>
[*] Waiting for messages. To exit press CTRL+C
[x] Received b'Hello World!'
[x] Received b'Hello World!'
注 这里就算重新运行 也会把之前的信息打印出来
更多推荐



所有评论(0)