props.put("bootstrap.servers", bootstrapServer);
props.put("group.id", groupId);
props.put("client.id", id);
+ props.put("enable.auto.commit", false);
props.put("auto.offset.reset", autoOffsetReset);
props.put("metadata.max.age.ms", "1000");
props.put("key.deserializer", StringDeserializer.class.getName());
removed.getPartition(),
counter.getKey());
}
- repository.save(new StatisticsDocument(removed));
+ repository.save(new StatisticsDocument(removed, consumer.position(tp)));
});
}
partitions.forEach(tp ->
{
log.info("{} - adding partition: {}", id, tp);
- seen.put(
- tp,
+ StatisticsDocument document =
repository
.findById(tp.toString())
- .map(PartitionStatistics::new)
- .orElse(new PartitionStatistics(tp)));
+ .orElse(new StatisticsDocument(tp));
+ consumer.seek(tp, document.offset);
+ seen.put(tp, new PartitionStatistics(document));
});
}
});
package de.juplo.kafka;
import lombok.ToString;
+import org.apache.kafka.common.TopicPartition;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
public String id;
public String topic;
public Integer partition;
+ public long offset;
public Map<String, Long> statistics;
public StatisticsDocument()
{
}
+ public StatisticsDocument(TopicPartition tp)
+ {
+ this.topic = tp.topic();
+ this.partition = tp.partition();
+ this.offset = 0;
+ }
+
public StatisticsDocument(String topic, Integer partition, Map<String, Long> statistics)
{
this.partition = partition;
this.statistics = statistics;
}
- public StatisticsDocument(PartitionStatistics statistics)
+ public StatisticsDocument(PartitionStatistics statistics, long offset)
{
this.topic = statistics.getPartition().topic();
this.id = statistics.toString();
this.partition = statistics.getPartition().partition();
+ this.offset = offset;
this.statistics = new HashMap<>();
statistics.getStatistics().forEach(counter -> this.statistics.put(counter.getKey(), counter.getResult()));
}