I am trying to integrate asyncio
functionality into my kafka topic listener and am running into issues (pretty new to async programming in python).
I have a confluent-kafka consumer
created that is listening to a topic. The topic has messages frequently and performance is of the utmost importance (hence the introduction of async io).
The main() function looks like this:
def main(self):
while True:
try:
msg = consumer.poll(timeout=5.0)
if msg is None:
continue
asyncio.ensure_future(handle_message(message))
finally:
consumer.close()
Essentially I want to pull messages off the topic in a linear fashion, but the handling of the message should be asynchronous...meaning that any database I/O etc that happens in handle_message
will be dealt with asynchronously (I have the awaits etc set up in that function properly). The problem is that it seems I never start execution in asyncio.ensure_future(). How do I continuously add tasks to an asynchronous loop as I pull messages from the kafka topic? Using confluent-kafka==1.5.0