Skip to content

Commit 4b10eb4

Browse files
JorgenRingenastubbs
authored andcommitted
Add option to specify timeout for how long to wait offset commits in periodic-consumer-sync commit-mode
Timeouts on commits will cause the control-loop to exit.
1 parent 9c2c55c commit 4b10eb4

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

parallel-consumer-core/src/main/java/io/confluent/parallelconsumer/ParallelConsumerOptions.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ public enum CommitMode {
169169
@Builder.Default
170170
private final Duration sendTimeout = Duration.ofSeconds(10);
171171

172+
/**
173+
* Controls how long to block while waiting for offsets to be committed.
174+
* Only relevant if using {@link CommitMode#PERIODIC_CONSUMER_SYNC} commit-mode.
175+
*/
176+
@Builder.Default
177+
private final Duration offsetCommitTimeout = Duration.ofSeconds(10);
178+
172179
public void validate() {
173180
Objects.requireNonNull(consumer, "A consumer must be supplied");
174181

parallel-consumer-core/src/main/java/io/confluent/parallelconsumer/internal/ConsumerOffsetCommitter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public class ConsumerOffsetCommitter<K, V> extends AbstractOffsetCommitter<K, V>
4242

4343
private final CommitMode commitMode;
4444

45+
private final Duration commitTimeout;
46+
4547
private Optional<Thread> owningThread = Optional.empty();
4648

4749
/**
@@ -57,6 +59,7 @@ public class ConsumerOffsetCommitter<K, V> extends AbstractOffsetCommitter<K, V>
5759
public ConsumerOffsetCommitter(final ConsumerManager<K, V> newConsumer, final WorkManager<K, V> newWorkManager, final ParallelConsumerOptions options) {
5860
super(newConsumer, newWorkManager);
5961
commitMode = options.getCommitMode();
62+
commitTimeout = options.getOffsetCommitTimeout();
6063
if (commitMode.equals(PERIODIC_TRANSACTIONAL_PRODUCER)) {
6164
throw new IllegalArgumentException("Cannot use " + commitMode + " when using " + this.getClass().getSimpleName());
6265
}
@@ -151,7 +154,7 @@ private void commitAndWait() {
151154
try {
152155
log.debug("Waiting on a commit response");
153156
Duration timeout = AbstractParallelEoSStreamProcessor.DEFAULT_TIMEOUT;
154-
CommitResponse take = commitResponseQueue.poll(timeout.toMillis(), TimeUnit.MILLISECONDS); // blocks, drain until we find our response
157+
CommitResponse take = commitResponseQueue.poll(commitTimeout.toMillis(), TimeUnit.MILLISECONDS); // blocks, drain until we find our response
155158
if (take == null)
156159
throw new InternalRuntimeError(msg("Timeout waiting for commit response {} to request {}", timeout, commitRequest));
157160
waitingOnCommitResponse = take.getRequest().getId() != commitRequest.getId();

0 commit comments

Comments
 (0)