@Autowired
KafkaConsumer<Bytes, Bytes> offsetConsumer;
@Autowired
- PartitionStatisticsRepository partitionStatisticsRepository;
- @Autowired
ApplicationProperties properties;
@Autowired
ExecutorService executor;
@Autowired
- PartitionStatisticsRepository repository;
+ StateRepository stateRepository;
@Autowired
- KeyCountingRebalanceListener keyCountingRebalanceListener;
+ ApplicationRebalanceListener rebalanceListener;
@Autowired
- KeyCountingRecordHandler keyCountingRecordHandler;
+ ApplicationRecordHandler recordHandler;
EndlessConsumer<String, Long> endlessConsumer;
Map<TopicPartition, Long> oldOffsets;
Long offset = offsetConsumer.position(tp);
log.info("New position for {}: {}", tp, offset);
Integer partition = tp.partition();
- StatisticsDocument document =
- partitionStatisticsRepository
+ StateDocument document =
+ stateRepository
.findById(partition.toString())
- .orElse(new StatisticsDocument(partition));
+ .orElse(new StateDocument(partition));
document.offset = offset;
- partitionStatisticsRepository.save(document);
+ stateRepository.save(document);
});
offsetConsumer.unsubscribe();
}
partitions().forEach(tp ->
{
String partition = Integer.toString(tp.partition());
- Optional<Long> offset = partitionStatisticsRepository.findById(partition).map(document -> document.offset);
+ Optional<Long> offset = stateRepository.findById(partition).map(document -> document.offset);
consumer.accept(tp, offset.orElse(0l));
});
}
});
TestRecordHandler<String, Long> captureOffsetAndExecuteTestHandler =
- new TestRecordHandler<String, Long>(keyCountingRecordHandler) {
+ new TestRecordHandler<String, Long>(recordHandler) {
@Override
public void onNewRecord(ConsumerRecord<String, Long> record)
{
properties.getClientId(),
properties.getTopic(),
kafkaConsumer,
- keyCountingRebalanceListener,
+ rebalanceListener,
captureOffsetAndExecuteTestHandler);
endlessConsumer.start();