orpiske commented on a change in pull request #428: URL: https://github.com/apache/camel-kafka-connector/pull/428#discussion_r484650640
########## File path: core/src/main/java/org/apache/camel/kafkaconnector/CamelSourceTask.java ########## @@ -119,53 +119,63 @@ public void start(Map<String, String> props) { } } + private long remaining(long startPollEpochMilli, long maxPollDuration) { + return maxPollDuration - (Instant.now().toEpochMilli() - startPollEpochMilli); + } + + @Override public synchronized List<SourceRecord> poll() { - long startPollEpochMilli = Instant.now().toEpochMilli(); + final long startPollEpochMilli = Instant.now().toEpochMilli(); + + long remaining = remaining(startPollEpochMilli, maxPollDuration); long collectedRecords = 0L; - List<SourceRecord> records = new ArrayList<>(); - while (collectedRecords < maxBatchPollSize && (Instant.now().toEpochMilli() - startPollEpochMilli) < maxPollDuration) { - Exchange exchange = consumer.receiveNoWait(); + List<SourceRecord> records = null; + while (collectedRecords < maxBatchPollSize && remaining > 0) { + Exchange exchange = consumer.receive(remaining); + if (exchange == null) { + remaining = remaining(startPollEpochMilli, maxPollDuration); + continue; + } + + if (records == null) { Review comment: +1 ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org