Class FlinkKafkaInternalProducer<K,​V>

  • All Implemented Interfaces:
    Closeable, AutoCloseable, org.apache.kafka.clients.producer.Producer<K,​V>

    @Internal
    public class FlinkKafkaInternalProducer<K,​V>
    extends org.apache.kafka.clients.producer.KafkaProducer<K,​V>
    A KafkaProducer that exposes private fields to allow resume producing from a given state.
    • Constructor Detail

      • FlinkKafkaInternalProducer

        public FlinkKafkaInternalProducer​(Properties properties)
      • FlinkKafkaInternalProducer

        public FlinkKafkaInternalProducer​(Properties properties,
                                          String transactionalId)
    • Method Detail

      • send

        public Future<org.apache.kafka.clients.producer.RecordMetadata> send​(org.apache.kafka.clients.producer.ProducerRecord<K,​V> record,
                                                                             org.apache.kafka.clients.producer.Callback callback)
        Specified by:
        send in interface org.apache.kafka.clients.producer.Producer<K,​V>
        Overrides:
        send in class org.apache.kafka.clients.producer.KafkaProducer<K,​V>
      • flush

        public void flush()
        Specified by:
        flush in interface org.apache.kafka.clients.producer.Producer<K,​V>
        Overrides:
        flush in class org.apache.kafka.clients.producer.KafkaProducer<K,​V>
      • beginTransaction

        public void beginTransaction()
                              throws org.apache.kafka.common.errors.ProducerFencedException
        Specified by:
        beginTransaction in interface org.apache.kafka.clients.producer.Producer<K,​V>
        Overrides:
        beginTransaction in class org.apache.kafka.clients.producer.KafkaProducer<K,​V>
        Throws:
        org.apache.kafka.common.errors.ProducerFencedException
      • abortTransaction

        public void abortTransaction()
                              throws org.apache.kafka.common.errors.ProducerFencedException
        Specified by:
        abortTransaction in interface org.apache.kafka.clients.producer.Producer<K,​V>
        Overrides:
        abortTransaction in class org.apache.kafka.clients.producer.KafkaProducer<K,​V>
        Throws:
        org.apache.kafka.common.errors.ProducerFencedException
      • commitTransaction

        public void commitTransaction()
                               throws org.apache.kafka.common.errors.ProducerFencedException
        Specified by:
        commitTransaction in interface org.apache.kafka.clients.producer.Producer<K,​V>
        Overrides:
        commitTransaction in class org.apache.kafka.clients.producer.KafkaProducer<K,​V>
        Throws:
        org.apache.kafka.common.errors.ProducerFencedException
      • isInTransaction

        public boolean isInTransaction()
      • hasRecordsInTransaction

        public boolean hasRecordsInTransaction()
      • isPrecommitted

        public boolean isPrecommitted()
      • precommitTransaction

        public void precommitTransaction()
      • close

        public void close()
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        Specified by:
        close in interface org.apache.kafka.clients.producer.Producer<K,​V>
        Overrides:
        close in class org.apache.kafka.clients.producer.KafkaProducer<K,​V>
      • close

        public void close​(Duration timeout)
        Specified by:
        close in interface org.apache.kafka.clients.producer.Producer<K,​V>
        Overrides:
        close in class org.apache.kafka.clients.producer.KafkaProducer<K,​V>
      • isClosed

        public boolean isClosed()
      • getTransactionalId

        @Nullable
        public String getTransactionalId()
      • getEpoch

        public short getEpoch()
      • getProducerId

        public long getProducerId()
      • setTransactionId

        public void setTransactionId​(String transactionalId)
        Sets the transactional id and sets the transaction manager state to uninitialized.

        Can only be called if the producer is not in a transaction.

      • resumeTransaction

        public void resumeTransaction​(long producerId,
                                      short epoch)
        Instead of obtaining producerId and epoch from the transaction coordinator, re-use previously obtained ones, so that we can resume transaction after a restart. Implementation of this method is based on KafkaProducer.initTransactions(). https://github.com/apache/kafka/commit/5d2422258cb975a137a42a4e08f03573c49a387e#diff-f4ef1afd8792cd2a2e9069cd7ddea630