Apache Kafka stores the message with offset. The following are several ways the messages can be retrieved with time;
Message Creation
When the message is created append the runtime to the message in the producer class before publishing the message to the topic as follows:
String runtime = new Date.toString();
String msg = "Test Message " + runtime;
KeyedMessage<String,String> data = new KeyedMessage<String, String> (topic,msg);
producer.send(data);
The message can be retrieved using the runtime timestamp.
Apache Kafka System Tools
...
The low level consumer API is stateless and provides fine grained control over the Kafka broker and the consumer.It allows consumers to set the message offset with every request raised to the broker and maintains the metadata on consumer's end. The topicsMetadata() method of kafka.javaapi.TopicMetadataResponse class is used to find the topic of interest from the lead broker. For message partition reading, the kafka.api.OffsetRequest
class defines two constants: EarliestTime
and LatestTime
, to find the beginning of the data in the logs and the new messages stream.
The following is the simple consumer API class diagram
...