I am using python 3.7 and confluent-kafka.
Following is the pseudo code which I am using to poll the kafka server and read the message.
while True:
MSG = CONSUMER.poll(0.1)
if MSG is None:
CONSUMER.commit()
print('No msg')
continue
if MSG.error():
print("Consumer error: {}".format(MSG.error()))
CONSUMER.commit()
continue
try:
rawMsg = format(MSG.value().decode('utf-8'))
testmsg = json.loads(rawMsg)
except:
print('invalid json format msg')
CONSUMER.commit()
If the kafka server is down or disconnected for some reason, I want an exception to be thrown.
Currently, if the above happens, the while loop keeps running without any error and prints No msg.
How do I get an exception or check if the kafka server can be connected each time in the loop (If there is some check to be made it should be lightweight).