orpiske commented on code in PR #14768:
URL: https://github.com/apache/camel/pull/14768#discussion_r1671678632


##########
components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaFetchRecords.java:
##########
@@ -343,6 +371,30 @@ protected void startPolling() {
             final KafkaRecordProcessorFacade recordProcessorFacade = 
createRecordProcessor();
 
             while (isKafkaConsumerRunnableAndNotStopped() && isConnected() && 
pollExceptionStrategy.canContinue()) {
+
+                if (commitRecordsRequested.compareAndSet(true, false)) {
+                    try {
+                        // we want to get details about last committed offsets 
(which MUST be done by this consumer thread)
+                        Map<TopicPartition, OffsetAndMetadata> commits = 
consumer.committed(consumer.assignment());
+                        commitRecords.clear();
+                        for (var e : commits.entrySet()) {
+                            KafkaTopicPosition p
+                                    = new KafkaTopicPosition(
+                                            e.getKey().topic(), 
e.getKey().partition(), e.getValue().offset(),
+                                            
e.getValue().leaderEpoch().orElse(0));
+                            commitRecords.add(p);
+                        }
+                        CountDownLatch count = latch.get();
+                        if (count != null) {
+                            count.countDown();
+                        }
+                    } catch (Exception e) {
+                        // ignore cannot get last commit details
+                        LOG.debug("Cannot get last offset committed from Kafka 
brokers due to: {}. This exception is ignored.",
+                                e.getMessage(), e);
+                    }
+                }
+

Review Comment:
   And the reason I suggested a decorator, is because if we have a NOOP one and 
a Console one, then we could give the JVM a chance to use DCE to eliminate the 
code without hurting the performance.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to