I need to get the message produced in Kafka hour by hour in a day. Every one hour I will launch a job to consume the message produced 1 hour ago. e.g., if current time is 20:12,
As the other replies note, older versions of Kafka had only an approximate way of mapping times to offsets. However, since Kafka 0.10.0 (released in May 2016), Kafka maintains a time index for each topic. This will allow you to efficiently get from times to exact offsets. You can use the KafkaConsumer#offsetsForTimes method to access this information.
There are more details about how the time-based index is implemented on the KIP-33 design discussion page.