title: How do I consume Kafka topic inside spark streaming app?
body: <p>When I create a stream from Kafka topic and print its content</p>
  
  <pre><code>    import os
      os.environ['PYSPARK_SUBMIT_ARGS'] = '--packages org.apache.spark:spark-streaming-kafka-0-8_2.11:2.0.2 pyspark-shell'
      from pyspark import SparkContext
      from pyspark.streaming import StreamingContext
      from pyspark.streaming.kafka import KafkaUtils
  
      sc = SparkContext(appName="PythonStreamingKafkaWords")
      ssc = StreamingContext(sc, 10)
  
      lines = KafkaUtils.createDirectStream(ssc, ['sample_topic'], {"bootstrap.servers": 'localhost:9092'})
  
      lines.pprint()
  
      ssc.start()
      ssc.awaitTermination()
  </code></pre>
  
  <p>I get an empty result</p>
  
  <pre><code>    -------------------------------------------
      Time: 2019-12-07 13:11:50
      -------------------------------------------
  
      -------------------------------------------
      Time: 2019-12-07 13:12:00
      -------------------------------------------
  
      -------------------------------------------
      Time: 2019-12-07 13:12:10
      -------------------------------------------
  </code></pre>
  
  <p>Meanwhile, it works in the console:</p>
  
  <pre><code>    kafka-console-consumer --topic sample_topic --from-beginning --bootstrap-server localhost:9092
  </code></pre>
  
  <p>correctly gives me all lines of my text in Kafka topic: </p>
  
  <pre><code>    ham Ok lor... Sony ericsson salesman... I ask shuhui then she say quite gd 2 use so i considering...
      ham Ard 6 like dat lor.
      ham Why don't you wait 'til at least wednesday to see if you get your .
      ham Huh y lei...
      spam    REMINDER FROM O2: To get 2.50 pounds free call credit and details of great offers pls reply 2 this text with your valid name, house no and postcode
      spam    This is the 2nd time we have tried 2 contact u. U have won the £750 Pound prize. 2 claim is easy, call 087187272008 NOW1! Only 10p per minute. BT-national-rate.
      ham Will ü b going to esplanade fr home?
      . . . 
  </code></pre>
  
  <p>What is the proper way to stream data from Kafka topic into Spark streaming app?</p>