Class KafkaProducer<K,​V>

    • Method Detail

      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • write

        public void write​(KafkaProducerRecord<K,​V> data)
        Same as but with an handler called when the operation completes
        Specified by:
        write in interface WriteStream<K>
        Parameters:
        data -
      • rxWrite

        public io.reactivex.Completable rxWrite​(KafkaProducerRecord<K,​V> data)
        Same as but with an handler called when the operation completes
        Specified by:
        rxWrite in interface WriteStream<K>
        Parameters:
        data -
        Returns:
      • end

        public void end​(KafkaProducerRecord<K,​V> data)
        Same as but with an handler called when the operation completes
        Specified by:
        end in interface WriteStream<K>
        Parameters:
        data -
      • rxEnd

        public io.reactivex.Completable rxEnd​(KafkaProducerRecord<K,​V> data)
        Same as but with an handler called when the operation completes
        Specified by:
        rxEnd in interface WriteStream<K>
        Parameters:
        data -
        Returns:
      • writeQueueFull

        public boolean writeQueueFull()
        This will return true if there are more bytes in the write queue than the value set using setWriteQueueMaxSize(int)
        Specified by:
        writeQueueFull in interface WriteStream<K>
        Returns:
        true if write queue is full
      • createShared

        public static <K,​V> KafkaProducer<K,​V> createShared​(Vertx vertx,
                                                                        String name,
                                                                        Map<String,​String> config)
        Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same name

        When close has been called for each shared producer the resources will be released. Calling end closes all shared producers.

        Parameters:
        vertx - Vert.x instance to use
        name - the producer name to identify it
        config - Kafka producer configuration
        Returns:
        an instance of the KafkaProducer
      • createShared

        public static <K,​V> KafkaProducer<K,​V> createShared​(Vertx vertx,
                                                                        String name,
                                                                        KafkaClientOptions options)
        Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same name

        When close has been called for each shared producer the resources will be released. Calling end closes all shared producers.

        Parameters:
        vertx - Vert.x instance to use
        name - the producer name to identify it
        options - Kafka producer options
        Returns:
        an instance of the KafkaProducer
      • createShared

        public static <K,​V> KafkaProducer<K,​V> createShared​(Vertx vertx,
                                                                        String name,
                                                                        Map<String,​String> config,
                                                                        Class<K> keyType,
                                                                        Class<V> valueType)
        Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same name

        When close has been called for each shared producer the resources will be released. Calling end closes all shared producers.

        Parameters:
        vertx - Vert.x instance to use
        name - the producer name to identify it
        config - Kafka producer configuration
        keyType - class type for the key serialization
        valueType - class type for the value serialization
        Returns:
        an instance of the KafkaProducer
      • createShared

        public static <K,​V> KafkaProducer<K,​V> createShared​(Vertx vertx,
                                                                        String name,
                                                                        KafkaClientOptions options,
                                                                        Class<K> keyType,
                                                                        Class<V> valueType)
        Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same name

        When close has been called for each shared producer the resources will be released. Calling end closes all shared producers.

        Parameters:
        vertx - Vert.x instance to use
        name - the producer name to identify it
        options - Kafka producer options
        keyType - class type for the key serialization
        valueType - class type for the value serialization
        Returns:
        an instance of the KafkaProducer
      • create

        public static <K,​V> KafkaProducer<K,​V> create​(Vertx vertx,
                                                                  Map<String,​String> config)
        Create a new KafkaProducer instance
        Parameters:
        vertx - Vert.x instance to use
        config - Kafka producer configuration
        Returns:
        an instance of the KafkaProducer
      • create

        public static <K,​V> KafkaProducer<K,​V> create​(Vertx vertx,
                                                                  Map<String,​String> config,
                                                                  Class<K> keyType,
                                                                  Class<V> valueType)
        Create a new KafkaProducer instance
        Parameters:
        vertx - Vert.x instance to use
        config - Kafka producer configuration
        keyType - class type for the key serialization
        valueType - class type for the value serialization
        Returns:
        an instance of the KafkaProducer
      • abortTransaction

        public KafkaProducer<K,​V> abortTransaction​(Handler<AsyncResult<Void>> handler)
        Aborts the ongoing transaction. See KafkaProducer
        Parameters:
        handler - handler called on operation completed
        Returns:
        current KafkaWriteStream instance
      • abortTransaction

        public KafkaProducer<K,​V> abortTransaction()
        Aborts the ongoing transaction. See KafkaProducer
        Returns:
        current KafkaWriteStream instance
      • rxAbortTransaction

        public io.reactivex.Completable rxAbortTransaction()
        Aborts the ongoing transaction. See KafkaProducer
        Returns:
        current KafkaWriteStream instance
      • setWriteQueueMaxSize

        public KafkaProducer<K,​V> setWriteQueueMaxSize​(int i)
        Description copied from interface: WriteStream
        Set the maximum size of the write queue to maxSize. You will still be able to write to the stream even if there is more than maxSize items in the write queue. This is used as an indicator by classes such as Pipe to provide flow control.

        The value is defined by the implementation of the stream, e.g in bytes for a NetSocket, etc...

        Specified by:
        setWriteQueueMaxSize in interface WriteStream<K>
        Parameters:
        i - the max size of the write stream
        Returns:
        a reference to this, so the API can be used fluently
      • drainHandler

        public KafkaProducer<K,​V> drainHandler​(Handler<Void> handler)
        Description copied from interface: WriteStream
        Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write queue is ready to accept buffers again. See Pipe for an example of this being used.

        The stream implementation defines when the drain handler, for example it could be when the queue size has been reduced to maxSize / 2.

        Specified by:
        drainHandler in interface WriteStream<K>
        Parameters:
        handler - the handler
        Returns:
        a reference to this, so the API can be used fluently
      • send

        public KafkaProducer<K,​V> send​(KafkaProducerRecord<K,​V> record)
        Asynchronously write a record to a topic
        Parameters:
        record - record to write
        Returns:
        current KafkaWriteStream instance
      • rxSend

        public io.reactivex.Single<RecordMetadata> rxSend​(KafkaProducerRecord<K,​V> record)
        Asynchronously write a record to a topic
        Parameters:
        record - record to write
        Returns:
        current KafkaWriteStream instance
      • partitionsFor

        public KafkaProducer<K,​V> partitionsFor​(String topic,
                                                      Handler<AsyncResult<List<PartitionInfo>>> handler)
        Get the partition metadata for the give topic.
        Parameters:
        topic - topic partition for which getting partitions info
        handler - handler called on operation completed
        Returns:
        current KafkaProducer instance
      • partitionsFor

        public KafkaProducer<K,​V> partitionsFor​(String topic)
        Get the partition metadata for the give topic.
        Parameters:
        topic - topic partition for which getting partitions info
        Returns:
        current KafkaProducer instance
      • rxPartitionsFor

        public io.reactivex.Single<List<PartitionInfo>> rxPartitionsFor​(String topic)
        Get the partition metadata for the give topic.
        Parameters:
        topic - topic partition for which getting partitions info
        Returns:
        current KafkaProducer instance
      • flush

        public KafkaProducer<K,​V> flush​(Handler<AsyncResult<Void>> completionHandler)
        Invoking this method makes all buffered records immediately available to write
        Parameters:
        completionHandler - handler called on operation completed
        Returns:
        current KafkaProducer instance
      • flush

        public KafkaProducer<K,​V> flush()
        Invoking this method makes all buffered records immediately available to write
        Returns:
        current KafkaProducer instance
      • rxFlush

        public io.reactivex.Completable rxFlush()
        Invoking this method makes all buffered records immediately available to write
        Returns:
        current KafkaProducer instance
      • close

        public void close​(Handler<AsyncResult<Void>> completionHandler)
        Close the producer
        Parameters:
        completionHandler - handler called on operation completed
      • close

        public void close()
        Close the producer
      • rxClose

        public io.reactivex.Completable rxClose()
        Close the producer
        Returns:
      • close

        public void close​(long timeout,
                          Handler<AsyncResult<Void>> completionHandler)
        Close the producer
        Parameters:
        timeout - timeout to wait for closing
        completionHandler - handler called on operation completed
      • close

        public void close​(long timeout)
        Close the producer
        Parameters:
        timeout - timeout to wait for closing
      • rxClose

        public io.reactivex.Completable rxClose​(long timeout)
        Close the producer
        Parameters:
        timeout - timeout to wait for closing
        Returns: