1

I am new to the python . I cant understand channel.start_consuming() is not working. my code

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)

Basic-handler definition

def basic_handler(ch, method, properties, body):
    global LOGGER
    global SHARES
    global HEIGHT
    print("I am reached here")
    /// some code
    sys.stdout.flush()

While i run i am getting . I mention some print statements in my code

<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

it did't print 2 - print("2") after the line " channel.start_consuming() " It is not going insde the definition "base_handler" mention in basic_consume.

I am not getting any exceptions

Sammu Sundar
  • 556
  • 3
  • 9
  • 24
  • 1
    start_consuming is blocking. So unless you specifically stop consuming (or the connection is closed) it won't move on to the next part. https://github.com/pika/pika/blob/master/pika/adapters/blocking_connection.py#L1834 – eandersson Mar 22 '19 at 07:17
  • @eandersson Thank you for the reply . Now i understand working concept of Rabbitmq :) – Sammu Sundar Mar 22 '19 at 11:06

0 Answers0