private final Consumer<String, String> consumer;
private Instant lastCommit = Instant.EPOCH;
+ private boolean commitsEnabled = true;
@Override
public void onPartitionsAssigned(Collection<TopicPartition> partitions)
id,
partition,
newOffset);
- repository.save(new StateDocument(partition, handler.removePartition(partition), newOffset));
+ if (commitsEnabled)
+ {
+ repository.save(new StateDocument(partition, handler.removePartition(partition), newOffset));
+ }
+ else
+ {
+ log.info("Offset commits are disabled! Last commit: {}", lastCommit);
+ }
});
}
@Override
public void beforeNextPoll()
{
+ if (!commitsEnabled)
+ {
+ log.info("Offset commits are disabled! Last commit: {}", lastCommit);
+ return;
+ }
+
if (lastCommit.plus(commitInterval).isBefore(clock.instant()))
{
log.debug("Storing data and offsets, last commit: {}", lastCommit);
lastCommit = clock.instant();
}
}
+
+ @Override
+ public void enableCommits()
+ {
+ commitsEnabled = true;
+ }
+
+ @Override
+ public void disableCommits()
+ {
+ commitsEnabled = false;
+ }
}
try
{
log.info("{} - Subscribing to topic {}", id, topic);
+ pollIntervalAwareRebalanceListener.enableCommits();
consumer.subscribe(Arrays.asList(topic), pollIntervalAwareRebalanceListener);
while (true)
}
catch(Exception e)
{
- log.error("{} - Unexpected error: {}", id, e.toString(), e);
+ log.error("{} - Unexpected error: {}, disabling commits", id, e.toString(), e);
+ pollIntervalAwareRebalanceListener.disableCommits();
shutdown(e);
}
finally