Class TransactionalProducer

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void abort​(com.networknt.kafka.producer.TransactionalProducer.KafkaTransactionState transaction)  
      static int addressToPartition​(String address)  
      com.networknt.kafka.producer.TransactionalProducer.KafkaTransactionState beginTransaction()  
      void close()
      This method is called by a shutdown hook to close the producer if it is not null.
      protected void commit​(com.networknt.kafka.producer.TransactionalProducer.KafkaTransactionState transaction)  
      com.networknt.kafka.producer.TransactionalProducer.KafkaTransactionState currentTransaction()  
      static <E> int drain​(BlockingQueue<E> q, Collection<? super E> buffer, int numElements, long timeout, TimeUnit unit)
      Drains the queue as BlockingQueue.drainTo(Collection, int), but if the requested numElements elements are not available, it will wait for them up to the specified timeout.
      BlockingQueue<org.apache.kafka.clients.producer.ProducerRecord<byte[],​byte[]>> getTxQueue()
      Get the blocking queue that is used to cache messages so that they can be sent in a batch.
      void invoke​(com.networknt.kafka.producer.TransactionalProducer.KafkaTransactionState transaction, String topic, org.apache.kafka.clients.producer.ProducerRecord<byte[],​byte[]> record)  
      void open()
      Initializes the connection to Kafka.
      protected void preCommit​(com.networknt.kafka.producer.TransactionalProducer.KafkaTransactionState transaction)  
      void propagateHeaders​(org.apache.kafka.clients.producer.ProducerRecord record, io.undertow.server.HttpServerExchange exchange)
      For each producer, it is responsible for populate the header of the ProducerRecord.
      protected void recoverAndAbort​(com.networknt.kafka.producer.TransactionalProducer.KafkaTransactionState transaction)  
      protected void recoverAndCommit​(com.networknt.kafka.producer.TransactionalProducer.KafkaTransactionState transaction)  
      void run()  
    • Constructor Detail

      • TransactionalProducer

        public TransactionalProducer()
    • Method Detail

      • getTxQueue

        public BlockingQueue<org.apache.kafka.clients.producer.ProducerRecord<byte[],​byte[]>> getTxQueue()
        Description copied from interface: QueuedLightProducer
        Get the blocking queue that is used to cache messages so that they can be sent in a batch.
        Specified by:
        getTxQueue in interface QueuedLightProducer
        Returns:
        the queue that contains the cached messages
      • run

        public void run()
        Specified by:
        run in interface Runnable
      • drain

        public static <E> int drain​(BlockingQueue<E> q,
                                    Collection<? super E> buffer,
                                    int numElements,
                                    long timeout,
                                    TimeUnit unit)
                             throws InterruptedException
        Drains the queue as BlockingQueue.drainTo(Collection, int), but if the requested numElements elements are not available, it will wait for them up to the specified timeout.
        Type Parameters:
        E - element
        Parameters:
        q - the blocking queue to be drained
        buffer - where to add the transferred elements
        numElements - the number of elements to be waited for
        timeout - how long to wait before giving up, in units of unit
        unit - a TimeUnit determining how to interpret the timeout parameter
        Returns:
        the number of elements transferred
        Throws:
        InterruptedException - if interrupted while waiting
      • commit

        protected void commit​(com.networknt.kafka.producer.TransactionalProducer.KafkaTransactionState transaction)
      • recoverAndCommit

        protected void recoverAndCommit​(com.networknt.kafka.producer.TransactionalProducer.KafkaTransactionState transaction)
      • abort

        protected void abort​(com.networknt.kafka.producer.TransactionalProducer.KafkaTransactionState transaction)
      • recoverAndAbort

        protected void recoverAndAbort​(com.networknt.kafka.producer.TransactionalProducer.KafkaTransactionState transaction)
      • close

        public void close()
        Description copied from interface: LightProducer
        This method is called by a shutdown hook to close the producer if it is not null.
        Specified by:
        close in interface LightProducer
      • currentTransaction

        public com.networknt.kafka.producer.TransactionalProducer.KafkaTransactionState currentTransaction()
      • propagateHeaders

        public void propagateHeaders​(org.apache.kafka.clients.producer.ProducerRecord record,
                                     io.undertow.server.HttpServerExchange exchange)
        Description copied from interface: QueuedLightProducer
        For each producer, it is responsible for populate the header of the ProducerRecord.
        Specified by:
        propagateHeaders in interface QueuedLightProducer
        Parameters:
        record - the ProducerRecord
        exchange - the Undertow exchange that carries HTTP headers
      • addressToPartition

        public static int addressToPartition​(String address)