channel.start_using()未运行,并且未提供任何异常

时间:2019-03-19 08:43:55

标签: python-3.x rabbitmq pika python-pika

我是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

它没有打印2-在“ channel.start_consumping()“行之后打印(” 2“) 不会插入basic_consume中提到的“ base_handler”定义。

我没有任何例外

0 个答案:

没有答案