Class KafkaProducer<K,​V>

    • Field Detail

      • __TYPE_ARG

        public static final io.vertx.lang.rx.TypeArg<KafkaProducer> __TYPE_ARG
      • __typeArg_0

        public final io.vertx.lang.rx.TypeArg<K> __typeArg_0
      • __typeArg_1

        public final io.vertx.lang.rx.TypeArg<V> __typeArg_1
    • Constructor Detail

      • KafkaProducer

        public KafkaProducer​(KafkaProducer delegate)
      • KafkaProducer

        public KafkaProducer​(Object delegate,
                             io.vertx.lang.rx.TypeArg<K> typeArg_0,
                             io.vertx.lang.rx.TypeArg<V> typeArg_1)
    • Method Detail

      • hashCode

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

        public Future<Void> write​(KafkaProducerRecord<K,​V> data)
        Write some data to the stream.

        The data is usually put on an internal write queue, and the write actually happens asynchronously. To avoid running out of memory by putting too much on the write queue, check the WriteStream.writeQueueFull() method before writing. This is done automatically if using a .

        When the data is moved from the queue to the actual medium, the returned will be completed with the write result, e.g the future is succeeded when a server HTTP response buffer is written to the socket and failed if the remote client has closed the socket while the data was still pending for write.

        Specified by:
        write in interface WriteStream<K>
        Parameters:
        data - the data to write
        Returns:
        a future completed with the write result
      • rxWrite

        public Completable rxWrite​(KafkaProducerRecord<K,​V> data)
        Write some data to the stream.

        The data is usually put on an internal write queue, and the write actually happens asynchronously. To avoid running out of memory by putting too much on the write queue, check the WriteStream.writeQueueFull() method before writing. This is done automatically if using a .

        When the data is moved from the queue to the actual medium, the returned will be completed with the write result, e.g the future is succeeded when a server HTTP response buffer is written to the socket and failed if the remote client has closed the socket while the data was still pending for write.

        Specified by:
        rxWrite in interface WriteStream<K>
        Parameters:
        data - the data to write
        Returns:
        a future completed with the write result
      • end

        public Future<Void> end()
        Ends the stream.

        Once the stream has ended, it cannot be used any more.

        Specified by:
        end in interface WriteStream<K>
        Returns:
        a future completed with the result
      • rxEnd

        public Completable rxEnd()
        Ends the stream.

        Once the stream has ended, it cannot be used any more.

        Specified by:
        rxEnd in interface WriteStream<K>
        Returns:
        a future completed with the result
      • 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
      • initTransactions

        public Future<Void> initTransactions()
        Initializes the underlying kafka transactional producer. See initTransactions() ()}
        Returns:
        a future notified with the result
      • rxInitTransactions

        public Completable rxInitTransactions()
        Initializes the underlying kafka transactional producer. See initTransactions() ()}
        Returns:
        a future notified with the result
      • beginTransaction

        public Future<Void> beginTransaction()
        Starts a new kafka transaction. See beginTransaction()
        Returns:
        a future notified with the result
      • rxBeginTransaction

        public Completable rxBeginTransaction()
        Starts a new kafka transaction. See beginTransaction()
        Returns:
        a future notified with the result
      • commitTransaction

        public Future<Void> commitTransaction()
        Commits the ongoing transaction. See commitTransaction()
        Returns:
        a future notified with the result
      • rxCommitTransaction

        public Completable rxCommitTransaction()
        Commits the ongoing transaction. See commitTransaction()
        Returns:
        a future notified with the result
      • abortTransaction

        public Future<Void> abortTransaction()
        Aborts the ongoing transaction. See KafkaProducer
        Returns:
        a future notified with the result
      • rxAbortTransaction

        public Completable rxAbortTransaction()
        Aborts the ongoing transaction. See KafkaProducer
        Returns:
        a future notified with the result
      • 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 Future<RecordMetadata> send​(KafkaProducerRecord<K,​V> record)
        Asynchronously write a record to a topic
        Parameters:
        record - record to write
        Returns:
        a Future completed with the record metadata
      • rxSend

        public Single<RecordMetadata> rxSend​(KafkaProducerRecord<K,​V> record)
        Asynchronously write a record to a topic
        Parameters:
        record - record to write
        Returns:
        a Future completed with the record metadata
      • partitionsFor

        public Future<List<PartitionInfo>> partitionsFor​(String topic)
        Get the partition metadata for the give topic.
        Parameters:
        topic - topic partition for which getting partitions info
        Returns:
        a future notified with the result
      • rxPartitionsFor

        public Single<List<PartitionInfo>> rxPartitionsFor​(String topic)
        Get the partition metadata for the give topic.
        Parameters:
        topic - topic partition for which getting partitions info
        Returns:
        a future notified with the result
      • flush

        public Future<Void> flush()
        Invoking this method makes all buffered records immediately available to write
        Returns:
        a future notified with the result
      • rxFlush

        public Completable rxFlush()
        Invoking this method makes all buffered records immediately available to write
        Returns:
        a future notified with the result
      • close

        public Future<Void> close()
        Close the producer
        Returns:
        a Future completed with the operation result
      • rxClose

        public Completable rxClose()
        Close the producer
        Returns:
        a Future completed with the operation result
      • close

        public Future<Void> close​(long timeout)
        Close the producer
        Parameters:
        timeout -
        Returns:
        a future notified with the result
      • rxClose

        public Completable rxClose​(long timeout)
        Close the producer
        Parameters:
        timeout -
        Returns:
        a future notified with the result
      • create

        public static <K,​V> KafkaProducer<K,​V> create​(Vertx vertx,
                                                                  org.apache.kafka.clients.producer.Producer<K,​V> producer)
        Create a new KafkaProducer instance from a native .
        Parameters:
        vertx - Vert.x instance to use
        producer - the Kafka producer to wrap
        Returns:
        an instance of the KafkaProducer
      • create

        public static <K,​V> KafkaProducer<K,​V> create​(Vertx vertx,
                                                                  org.apache.kafka.clients.producer.Producer<K,​V> producer,
                                                                  KafkaClientOptions options)
        Create a new KafkaProducer instance from a native .
        Parameters:
        vertx - Vert.x instance to use
        producer - the Kafka producer to wrap
        options - options used only for tracing settings
        Returns:
        an instance of the KafkaProducer
      • newInstance

        public static <K,​V> KafkaProducer<K,​V> newInstance​(KafkaProducer arg,
                                                                       io.vertx.lang.rx.TypeArg<K> __typeArg_K,
                                                                       io.vertx.lang.rx.TypeArg<V> __typeArg_V)