我是 python 新手。我无法理解channel.start_consuming()
不工作。我的代码
def functions(host):
global LOGGER
global RABBITMQ_USER
global RABBITMQ_PASSWORD
while True:
try:
credentials = pika.PlainCredentials(RABBITMQ_USER, RABBITMQ_PASSWORD)
connection = pika.BlockingConnection(pika.ConnectionParameters(
host=host,
credentials=credentials))
print(connection)
channel = connection.channel()
channel.basic_qos(prefetch_size=0, prefetch_count=0, all_channels=True)
channel.basic_consume(basic_handler,
queue='grinshares',
no_ack=False)
channel.basic_consume(basic_handler,
queue='poolshares',
no_ack=False)
print("1")
channel.start_consuming()
print("2")
except Exception as e:
LOGGER.error("Something went wrong: {}\n{}".format(e, traceback.format_exc().splitlines()))
sys.stdout.flush()
time.sleep(10)
基本处理程序定义
def basic_handler(ch, method, properties, body):
global LOGGER
global SHARES
global HEIGHT
print("I am reached here")
/// some code
sys.stdout.flush()
当我跑步时,我得到了。我在我的代码中提到了一些打印语句
<BlockingConnection impl=<SelectConnection OPEN socket=('127.0.0.1', 40068)->('127.0.0.1', 5672) params=<ConnectionParameters host=
localhost port=5672 virtual_host=/ ssl=False>>>
1
它没有在“channel.start_sumption()”行之后打印 2 - print("2") 它不会进入 basic_consume 中提到的定义“base_handler”。
我没有得到任何例外