Class KafkaProducer<K,V>

java.lang.Object
io.vertx.mutiny.kafka.client.producer.KafkaProducer<K,V>
All Implemented Interfaces:
MutinyDelegate, StreamBase, WriteStream<KafkaProducerRecord<K,V>>

public class KafkaProducer<K,V> extends Object implements WriteStream<KafkaProducerRecord<K,V>>, MutinyDelegate
Vert.x Kafka producer.

The WriteStream.write(Object) provides global control over writing a record.

NOTE: This class has been automatically generated from the original non Mutiny-ified interface.

See Also:
  • KafkaProducer
  • Field Details

  • Constructor Details

    • KafkaProducer

      public KafkaProducer(io.vertx.kafka.client.producer.KafkaProducer<K,V> delegate)
      Create a new instance of KafkaProducer delegating to the given (non-null) instance of KafkaProducer.
    • KafkaProducer

      public KafkaProducer(io.vertx.kafka.client.producer.KafkaProducer<K,V> delegate, TypeArg<K> typeArg_0, TypeArg<V> typeArg_1)
    • KafkaProducer

      public KafkaProducer(Object delegate, TypeArg<K> typeArg_0, TypeArg<V> typeArg_1)
  • Method Details

    • getDelegate

      public io.vertx.kafka.client.producer.KafkaProducer<K,V> getDelegate()
      Get the delegate instance.

      This method returns the instance on which this shim is delegating the calls. And so, give you access to the bare API.

      Specified by:
      getDelegate in interface MutinyDelegate
      Specified by:
      getDelegate in interface StreamBase
      Specified by:
      getDelegate in interface WriteStream<K>
      Returns:
      the delegate instance
    • initTransactions

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> initTransactions()
      Initializes the underlying kafka transactional producer. See initTransactions() ()}

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • KafkaProducer.initTransactions()
    • initTransactionsAndAwait

      public void initTransactionsAndAwait()
      Initializes the underlying kafka transactional producer. See initTransactions() ()}

      Unlike the bare Vert.x variant, this method returns a Void. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      See Also:
      • KafkaProducer.initTransactions()
    • initTransactionsAndForget

      public KafkaProducer<K,V> initTransactionsAndForget()
      Initializes the underlying kafka transactional producer. See initTransactions() ()}

      Unlike the bare Vert.x variant, this method ignores the Void result or any failure.

      Returns:
      The current instance to chain operations if needed.
      See Also:
      • KafkaProducer.initTransactions()
    • beginTransaction

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> beginTransaction()
      Starts a new kafka transaction. See beginTransaction()

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • KafkaProducer.beginTransaction()
    • beginTransactionAndAwait

      public void beginTransactionAndAwait()
      Starts a new kafka transaction. See beginTransaction()

      Unlike the bare Vert.x variant, this method returns a Void. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      See Also:
      • KafkaProducer.beginTransaction()
    • beginTransactionAndForget

      public KafkaProducer<K,V> beginTransactionAndForget()
      Starts a new kafka transaction. See beginTransaction()

      Unlike the bare Vert.x variant, this method ignores the Void result or any failure.

      Returns:
      The current instance to chain operations if needed.
      See Also:
      • KafkaProducer.beginTransaction()
    • commitTransaction

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> commitTransaction()
      Commits the ongoing transaction. See commitTransaction()

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • KafkaProducer.commitTransaction()
    • commitTransactionAndAwait

      public void commitTransactionAndAwait()
      Commits the ongoing transaction. See commitTransaction()

      Unlike the bare Vert.x variant, this method returns a Void. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      See Also:
      • KafkaProducer.commitTransaction()
    • commitTransactionAndForget

      public KafkaProducer<K,V> commitTransactionAndForget()
      Commits the ongoing transaction. See commitTransaction()

      Unlike the bare Vert.x variant, this method ignores the Void result or any failure.

      Returns:
      The current instance to chain operations if needed.
      See Also:
      • KafkaProducer.commitTransaction()
    • abortTransaction

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> abortTransaction()
      Aborts the ongoing transaction. See KafkaProducer.abortTransaction()

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • KafkaProducer.abortTransaction()
    • abortTransactionAndAwait

      public void abortTransactionAndAwait()
      Aborts the ongoing transaction. See KafkaProducer.abortTransaction()

      Unlike the bare Vert.x variant, this method returns a Void. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      See Also:
      • KafkaProducer.abortTransaction()
    • abortTransactionAndForget

      public KafkaProducer<K,V> abortTransactionAndForget()
      Aborts the ongoing transaction. See KafkaProducer.abortTransaction()

      Unlike the bare Vert.x variant, this method ignores the Void result or any failure.

      Returns:
      The current instance to chain operations if needed.
      See Also:
      • KafkaProducer.abortTransaction()
    • send

      @CheckReturnValue public io.smallrye.mutiny.Uni<io.vertx.kafka.client.producer.RecordMetadata> send(KafkaProducerRecord<K,V> record)
      Asynchronously write a record to a topic

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Parameters:
      record - record to write
      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • io.vertx.kafka.client.producer.KafkaProducer#send(KafkaProducerRecord)
    • sendAndAwait

      public io.vertx.kafka.client.producer.RecordMetadata sendAndAwait(KafkaProducerRecord<K,V> record)
      Asynchronously write a record to a topic

      Unlike the bare Vert.x variant, this method returns a RecordMetadata. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Parameters:
      record - record to write
      Returns:
      The operation result
      See Also:
      • io.vertx.kafka.client.producer.KafkaProducer#send(KafkaProducerRecord)
    • sendAndForget

      public KafkaProducer<K,V> sendAndForget(KafkaProducerRecord<K,V> record)
      Asynchronously write a record to a topic

      Unlike the bare Vert.x variant, this method ignores the RecordMetadata result or any failure.

      Parameters:
      record - record to write
      Returns:
      The current instance to chain operations if needed.
      See Also:
      • io.vertx.kafka.client.producer.KafkaProducer#send(KafkaProducerRecord)
    • partitionsFor

      @CheckReturnValue public io.smallrye.mutiny.Uni<List<io.vertx.kafka.client.common.PartitionInfo>> partitionsFor(String topic)
      Get the partition metadata for the give topic.

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Parameters:
      topic - topic partition for which getting partitions info
      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • KafkaProducer.partitionsFor(String)
    • partitionsForAndAwait

      public List<io.vertx.kafka.client.common.PartitionInfo> partitionsForAndAwait(String topic)
      Get the partition metadata for the give topic.

      Unlike the bare Vert.x variant, this method returns a List<io.vertx.kafka.client.common.PartitionInfo>. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Parameters:
      topic - topic partition for which getting partitions info
      Returns:
      The operation result
      See Also:
      • KafkaProducer.partitionsFor(String)
    • partitionsForAndForget

      public KafkaProducer<K,V> partitionsForAndForget(String topic)
      Get the partition metadata for the give topic.

      Unlike the bare Vert.x variant, this method ignores the List<io.vertx.kafka.client.common.PartitionInfo> result or any failure.

      Parameters:
      topic - topic partition for which getting partitions info
      Returns:
      The current instance to chain operations if needed.
      See Also:
      • KafkaProducer.partitionsFor(String)
    • flush

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> flush()
      Invoking this method makes all buffered records immediately available to write

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • KafkaProducer.flush()
    • flushAndAwait

      public void flushAndAwait()
      Invoking this method makes all buffered records immediately available to write

      Unlike the bare Vert.x variant, this method returns a Void. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      See Also:
      • KafkaProducer.flush()
    • flushAndForget

      public KafkaProducer<K,V> flushAndForget()
      Invoking this method makes all buffered records immediately available to write

      Unlike the bare Vert.x variant, this method ignores the Void result or any failure.

      Returns:
      The current instance to chain operations if needed.
      See Also:
      • KafkaProducer.flush()
    • close

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> close()
      Close the producer

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • KafkaProducer.close()
    • closeAndAwait

      public void closeAndAwait()
      Close the producer

      Unlike the bare Vert.x variant, this method returns a Void. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      See Also:
      • KafkaProducer.close()
    • closeAndForget

      public KafkaProducer<K,V> closeAndForget()
      Close the producer

      Unlike the bare Vert.x variant, this method ignores the Void result or any failure.

      Returns:
      The current instance to chain operations if needed.
      See Also:
      • KafkaProducer.close()
    • close

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> close(long timeout)
      Close the producer

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • KafkaProducer.close(long)
    • closeAndAwait

      public void closeAndAwait(long timeout)
      Close the producer

      Unlike the bare Vert.x variant, this method returns a Void. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      See Also:
      • KafkaProducer.close(long)
    • closeAndForget

      public KafkaProducer<K,V> closeAndForget(long timeout)
      Close the producer

      Unlike the bare Vert.x variant, this method ignores the Void result or any failure.

      Returns:
      The current instance to chain operations if needed.
      See Also:
      • KafkaProducer.close(long)
    • write

      @CheckReturnValue public io.smallrye.mutiny.Uni<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 writeQueueFull() method before writing. This is done automatically if using a Pipe.

      When the data is moved from the queue to the actual medium, the returned Future will be completed with the write result, e.g the uni 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.

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Specified by:
      write in interface WriteStream<K>
      Parameters:
      data - the data to write
      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • WriteStream.write(T)
    • writeAndAwait

      public void writeAndAwait(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 writeQueueFull() method before writing. This is done automatically if using a Pipe.

      When the data is moved from the queue to the actual medium, the returned Future will be completed with the write result, e.g the underlying uni 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.

      Unlike the bare Vert.x variant, this method returns a Void. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Parameters:
      data - the data to write
      See Also:
      • WriteStream.write(T)
    • writeAndForget

      public KafkaProducer<K,V> writeAndForget(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 writeQueueFull() method before writing. This is done automatically if using a Pipe.

      When the data is moved from the queue to the actual medium, the returned Future will be completed with the write result, e.g the underlying uni 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.

      Unlike the bare Vert.x variant, this method ignores the Void result or any failure.

      Parameters:
      data - the data to write
      Returns:
      The current instance to chain operations if needed.
      See Also:
      • WriteStream.write(T)
    • end

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> end(KafkaProducerRecord<K,V> data)
      Same as end() but writes some data to the stream before ending.

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Specified by:
      end in interface WriteStream<K>
      Parameters:
      data - the data to write
      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • WriteStream.end(T)
    • endAndAwait

      public void endAndAwait(KafkaProducerRecord<K,V> data)
      Same as end() but writes some data to the stream before ending.

      Unlike the bare Vert.x variant, this method returns a Void. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Parameters:
      data - the data to write
      See Also:
      • WriteStream.end(T)
    • endAndForget

      public KafkaProducer<K,V> endAndForget(KafkaProducerRecord<K,V> data)
      Same as end() but writes some data to the stream before ending.

      Unlike the bare Vert.x variant, this method ignores the Void result or any failure.

      Parameters:
      data - the data to write
      Returns:
      The current instance to chain operations if needed.
      See Also:
      • WriteStream.end(T)
    • end

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> end()
      Ends the stream.

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

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Specified by:
      end in interface WriteStream<K>
      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • WriteStream.end()
    • endAndAwait

      public void endAndAwait()
      Ends the stream.

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

      Unlike the bare Vert.x variant, this method returns a Void. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      See Also:
      • WriteStream.end()
    • endAndForget

      public KafkaProducer<K,V> endAndForget()
      Ends the stream.

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

      Unlike the bare Vert.x variant, this method ignores the Void result or any failure.

      Returns:
      The current instance to chain operations if needed.
      See Also:
      • WriteStream.end()
    • 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, io.vertx.kafka.client.common.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, io.vertx.kafka.client.common.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, org.apache.kafka.clients.producer.Producer<K,V> producer)
      Create a new KafkaProducer instance from a native Producer.
      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, io.vertx.kafka.client.common.KafkaClientOptions options)
      Create a new KafkaProducer instance from a native Producer.
      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
    • 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
    • exceptionHandler

      public KafkaProducer<K,V> exceptionHandler(Consumer<Throwable> handler)
      Description copied from interface: WriteStream
      Set an exception handler on the write stream.
      Specified by:
      exceptionHandler in interface StreamBase
      Specified by:
      exceptionHandler in interface WriteStream<K>
      Parameters:
      handler - the exception handler. Can be null.
      Returns:
      a reference to this, so the API can be used fluently
    • 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(Runnable 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. Can be null.
      Returns:
      a reference to this, so the API can be used fluently
    • 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
    • newInstance

      public static <K, V> KafkaProducer<K,V> newInstance(io.vertx.kafka.client.producer.KafkaProducer<K,V> delegate)
      Creates a new instance of the KafkaProducer.
    • newInstance

      public static <K, V> KafkaProducer<K,V> newInstance(io.vertx.kafka.client.producer.KafkaProducer<K,V> delegate, TypeArg<K> typeArg_0, TypeArg<V> typeArg_1)
      Creates a new instance of the KafkaProducer.
    • hashCode

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

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toSubscriber

      @CheckReturnValue public Flow.Subscriber<KafkaProducerRecord<K,V>> toSubscriber()
      Converts the current write stream to a subscriber.