Github user markap14 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1097#discussion_r82194639
  
    --- Diff: 
nifi-nar-bundles/nifi-kafka-bundle/nifi-kafka-0-10-processors/src/main/java/org/apache/nifi/processors/kafka/pubsub/PublisherLease.java
 ---
    @@ -0,0 +1,132 @@
    +/*
    + * 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.processors.kafka.pubsub;
    +
    +import java.io.Closeable;
    +import java.io.IOException;
    +import java.io.InputStream;
    +import java.util.concurrent.TimeUnit;
    +import java.util.concurrent.TimeoutException;
    +
    +import org.apache.kafka.clients.producer.Callback;
    +import org.apache.kafka.clients.producer.Producer;
    +import org.apache.kafka.clients.producer.ProducerRecord;
    +import org.apache.kafka.clients.producer.RecordMetadata;
    +import org.apache.nifi.flowfile.FlowFile;
    +import org.apache.nifi.logging.ComponentLog;
    +import org.apache.nifi.stream.io.exception.TokenTooLargeException;
    +import org.apache.nifi.stream.io.util.StreamDemarcator;
    +
    +public class PublisherLease implements Closeable {
    +    private final ComponentLog logger;
    +    private final Producer<byte[], byte[]> producer;
    +    private final int maxMessageSize;
    +    private final long maxAckWaitMillis;
    +    private volatile boolean poisoned = false;
    +
    +    private InFlightMessageTracker tracker;
    +
    +    public PublisherLease(final Producer<byte[], byte[]> producer, final 
int maxMessageSize, final long maxAckWaitMillis, final ComponentLog logger) {
    +        this.producer = producer;
    +        this.maxMessageSize = maxMessageSize;
    +        this.logger = logger;
    +        this.maxAckWaitMillis = maxAckWaitMillis;
    +    }
    +
    +    protected void poison() {
    +        this.poisoned = true;
    +    }
    +
    +    public boolean isPoisoned() {
    +        return poisoned;
    +    }
    +
    +    void publish(final FlowFile flowFile, final InputStream 
flowFileContent, final byte[] messageKey, final byte[] demarcatorBytes, final 
String topic) throws IOException {
    +        if (tracker == null) {
    --- End diff --
    
    We probably could... but I held off on doing that, because it may get 
poisoned in a background thread, and the caller may not know when calling 
publish() that it was poisoned. If that happens, the new FlowFile is likely to 
fail anyway. If it doesn't then it's okay - there's no reason it can't get 
published to Kafka at that point. We simply poison the lease to ensure that a 
new one gets created, in case there's an issue with the connection.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to