title: Kafka consumer with Flask Rest API is not listening with latest messages
body: <p>What I actually need is producer needs to send messages in an API and at that instant the consumer has to consume and display.</p>
  
  <p>I have tried all the options sometimes it works and sometimes it do not work </p>
  
  <pre><code>from flask import Flask, request
  app = Flask(__name__)
  
  def get_consumer():
      consumer = KafkaConsumer(group_id='1',
                            bootstrap_servers=['localhost:9092'],
                            auto_offset_reset='latest',
                            enable_auto_commit=False,
                            consumer_timeout_ms=-1,
                            max_poll_records=100)
      consumer.subscribe('my_topic')
  
      for m in consumer:
          print(m.value)
  
  app.route('/get_data',methods=["GET"])
  def get_data():
      get_consumer()
  </code></pre>
  
  <p>I am writing a rest API for Kafka consumer to listen to the latest messages which it is not displaying.</p>