title: Get kafka record timestamp from kafka message
body: <p><strong>I want the timestamp at which the message was inserted in kafka topic by producer.</strong></p>
  <p>And at the kafka consumer side, i want to extract that timestamp.</p>
  <pre><code>
  class Producer {
    def main(args: Array[String]): Unit = {
      writeToKafka(&quot;quick-start&quot;)
    }
    def writeToKafka(topic: String): Unit = {
      val props = new Properties()
      props.put(&quot;bootstrap.servers&quot;, &quot;localhost:9094&quot;)
      props.put(&quot;key.serializer&quot;, &quot;org.apache.kafka.common.serialization.StringSerializer&quot;)
      props.put(&quot;value.serializer&quot;, &quot;org.apache.kafka.common.serialization.StringSerializer&quot;)
      val producer = new KafkaProducer[String, String](props)
      val record = new ProducerRecord[String, String](topic, &quot;key&quot;, &quot;value&quot;)
      producer.send(record)
      producer.close()
    }
  }
  
  
  
  class Consumer {
    def main(args: Array[String]): Unit = {
      consumeFromKafka(&quot;quick-start&quot;)
    }
    def consumeFromKafka(topic: String) = {
      val props = new Properties()
      props.put(&quot;bootstrap.servers&quot;, &quot;localhost:9094&quot;)
      props.put(&quot;key.deserializer&quot;, &quot;org.apache.kafka.common.serialization.StringDeserializer&quot;)
      props.put(&quot;value.deserializer&quot;, &quot;org.apache.kafka.common.serialization.StringDeserializer&quot;)
      props.put(&quot;auto.offset.reset&quot;, &quot;latest&quot;)
      props.put(&quot;group.id&quot;, &quot;consumer-group&quot;)
      val consumer: KafkaConsumer[String, String] = new KafkaConsumer[String, String](props)
      consumer.subscribe(util.Arrays.asList(topic))
      while (true) {
        val record = consumer.poll(1000).asScala
        for (data &lt;- record.iterator)
          println(data.value())
      }
    }
  }
  </code></pre>
  <p><strong>Does kafka provides a way to do it? Else i will have to send an extra field from producer to topic.</strong></p>