error: http2: client connection lost while connecting to rabbitmq in python through kubernetes service

1/6/2022

I have deployed python script in azure kubernetes services which will make connection with rabbitmq to get input data and process it and pass the output data back to the rabbitmq in the form of messages , but i am getting below error when there is no data or messages in the queue for long time , i want my script should wait until data comes in rabbitmq

below is the error:

error: http2: client connection lost

Below is my code to connect with rabbitmq in python

    def callback(ch, method, properties, body):
try:
    rabbit_data=[]
    ch.exchange_declare(exchange='DataEx', exchange_type='fanout',durable=True)

    if body != None:
    
        rabbit_data.append(body)
    
        if len(rabbit_data) > 0:    
        
            for i in rabbit_data:
                final_packet=call_it(i)
                if final_packet:
                    a_logger.info(str(len(final_packet)))
            
                #out = { "reading_data": json.loads(a),
                #      "emission_data":json.loads(b)}   
                    for data_output in final_packet: 
                
                
                        ch.basic_publish(exchange='DataEx',routing_key='',
                                 body=json.dumps(data_output),
                                 properties=pika.BasicProperties(
                                     content_type="text/plain",
                                     delivery_mode=2))
                
                #
                    rabbit_data.remove(i)
                else:
                #ch.basic_reject(delivery_tag = method.delivery_tag,requeue=True)
                    pass
    else:
        ch.stop_consuming()
    
    ch.basic_ack(delivery_tag = method.delivery_tag,multiple=False) 
except Exception as e:
    a_logger.info("error in rabbitmq callback as : {}".format(str(e)))
    credentials = pika.PlainCredentials(username, password)
    parameters = pika.ConnectionParameters(host=Api_url,virtual_host=rmqvhost,credentials=credentials,heartbeat=0)
    print (username,password)

    connection = pika.BlockingConnection(parameters)
    channel = connection.channel()

    channel.queue_declare(queue='Plume',durable=True)


    channel.basic_qos(prefetch_size=0,prefetch_count=1) # this is for acknowdeging packet one by one 
    channel.basic_consume(queue='Plume', on_message_callback=callback,auto_ack=False)


    a_logger.info(' [*] Waiting for messages. To exit press CTRL+C')
    channel.start_consuming()
-- vishal
azure
kubernetes
pika
python
rabbitmq

0 Answers