# -*- 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!'

注 这里就算重新运行 也会把之前的信息打印出来

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐