greyp9 commented on code in PR #8463:
URL: https://github.com/apache/nifi/pull/8463#discussion_r1538315024


##########
nifi-nar-bundles/nifi-kafka-bundle/nifi-kafka-3-service/src/main/java/org/apache/nifi/kafka/service/producer/ProducerCallback.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.kafka.service.producer;
+
+import org.apache.kafka.clients.producer.Callback;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.kafka.service.api.producer.FlowFileResult;
+import org.apache.nifi.kafka.service.api.producer.ProducerRecordMetadata;
+import org.apache.nifi.kafka.shared.util.Notifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Supplier;
+
+public class ProducerCallback implements Callback {
+    private final Logger logger = LoggerFactory.getLogger(getClass());
+
+    private final AtomicLong sentCount;
+    private final AtomicLong acknowledgedCount;
+    private final AtomicLong failedCount;
+    private final FlowFile flowFile;
+    private final List<ProducerRecordMetadata> metadatas;
+    private final List<Exception> exceptions;
+    private final Notifier notifier;
+
+    public List<Exception> getExceptions() {
+        return exceptions;
+    }
+
+    public boolean isFailure() {
+        return !exceptions.isEmpty();
+    }
+
+    public ProducerCallback(final FlowFile flowFile) {
+        this.sentCount = new AtomicLong(0L);
+        this.acknowledgedCount = new AtomicLong(0L);
+        this.failedCount = new AtomicLong(0L);
+        this.flowFile = flowFile;
+        this.metadatas = new ArrayList<>();
+        this.exceptions = new ArrayList<>();
+        this.notifier = new Notifier();
+    }
+
+    public long send() {
+        return sentCount.incrementAndGet();
+    }
+
+    @Override
+    public void onCompletion(final RecordMetadata metadata, final Exception 
exception) {
+
+        // the source `FlowFile` and the associated `RecordMetadata` need to 
somehow be associated...

Review Comment:
   I was originally hoping that this sort of API would not be needed, but there 
were problems when I added transactionality.  Maybe a reasonable method-level 
comment could be used instead to capture this nuance?
   



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