If your Kafka messages have a proper timestamp, then you can get the offsets for the timestamp of the previous week. So you can use..
Map<TopicPartition,OffsetAndTimestamp> offsetsForTimes(Map<TopicPartition,Long> timestampsToSearch)
The documentation says:
Look up the offsets for the given partitions by timestamp. The
returned offset for each partition is the earliest offset whose
timestamp is greater than or equal to the given timestamp in the
corresponding partition.
For getting the list of topic partitions, you can call consumer.assignment() (after subscribe() or assign()) which returns Set<TopicPartition> assigned to the consumer. The Long value in the map is basically, the timestamp. So, for all keys in your case, it will be the same value (i.e. 1 week old timestamp)
Now, that you have got a Map<TopicPartition, OffsetAndTimestamp>. You can now use seek(TopicPartition partition, long offset) to seek to each offset.
consumer.subscribe(topics);
Set<TopicPartition> partitions = consumer.assignment();
Map<TopicPartition, Long> map = new LinkedHashMap<>();
partitions.forEach(partition -> map.put(partition, oneWeekOldTimestamp));
Map<TopicPartition, OffsetAndTimestamp> offsetsMap = consumer.offsetForTimes(map);
offsetsMap.forEach((partition, offsetTimestamp) -> consumer.seek(partition, offsetTimestamp.offset()));
Now, your consumer will be at position of messages that have been one week old. So, when you poll(), you poll from last week till now.
You can change your timestamp to meet your requirements, for example, anything older than 1 week means, from timestamp 0 to last week timestamp.
All previous week data means, 2weekOldTimestamp - 1weekOldTimestamp.
So, in this case you have to seek to 2weekOldTimestamp and then process each partition till you encounter 1weekOldTimestamp