use of org.apache.kafka.clients.consumer.OffsetAndMetadata in project apex-malhar by apache.
the class KafkaConsumerWrapper method commitOffsets.
/**
* Only put the offset needs to be committed in the ConsumerThread.offsetToCommit map
* The consumer thread will commit the offset(s)
*
* @param offsetsInWindow
*/
public void commitOffsets(Map<AbstractKafkaPartitioner.PartitionMeta, Long> offsetsInWindow) {
if (offsetsInWindow == null) {
return;
}
// group offsets by cluster and topic partition
for (Map.Entry<AbstractKafkaPartitioner.PartitionMeta, Long> e : offsetsInWindow.entrySet()) {
String cluster = e.getKey().getCluster();
Map<TopicPartition, OffsetAndMetadata> topicPartitionOffsetMap = offsetsToCommit.get(cluster);
if (topicPartitionOffsetMap == null) {
logger.warn("committed offset map should be initialized by consumer thread!");
continue;
}
topicPartitionOffsetMap.put(e.getKey().getTopicPartition(), new OffsetAndMetadata(e.getValue()));
}
}
Aggregations