io.vertx.kafka.client.producer

## Interface KafkaProducer<K,V>

- All Superinterfaces:
    StreamBase, WriteStream<KafkaProducerRecord<K,V>>

      public interface KafkaProducer<K,V>
      extends WriteStream<KafkaProducerRecord<K,V>>

  Vert.x Kafka producer.

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

- - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `Future<Void>` | `abortTransaction()` Like `abortTransaction(Handler)` but with a future of the result
    `KafkaProducer<K,V>` | `abortTransaction(Handler<AsyncResult<Void>> handler)` Aborts the ongoing transaction.
    `KafkaWriteStream<K,V>` | `asStream()`
    `Future<Void>` | `beginTransaction()` Like `beginTransaction(Handler)` but with a future of the result
    `KafkaProducer<K,V>` | `beginTransaction(Handler<AsyncResult<Void>> handler)` Starts a new kafka transaction.
    `Future<Void>` | `close()` Close the producer
    `void` | `close(Handler<AsyncResult<Void>> completionHandler)` Close the producer
    `Future<Void>` | `close(long timeout)` Like `close(long, Handler)` but returns a `Future` of the asynchronous result
    `void` | `close(long timeout, Handler<AsyncResult<Void>> completionHandler)` Close the producer
    `Future<Void>` | `commitTransaction()` Like `commitTransaction(Handler)` but with a future of the result
    `KafkaProducer<K,V>` | `commitTransaction(Handler<AsyncResult<Void>> handler)` Commits the ongoing transaction.
    `static <K,V> KafkaProducer<K,V>` | `create(Vertx vertx, Map<String,String> config)` Create a new KafkaProducer instance
    `static <K,V> KafkaProducer<K,V>` | `create(Vertx vertx, Map<String,String> config, Class<K> keyType, Class<V> valueType)` Create a new KafkaProducer instance
    `static <K,V> KafkaProducer<K,V>` | `create(Vertx vertx, Map<String,String> config, org.apache.kafka.common.serialization.Serializer<K> keySerializer, org.apache.kafka.common.serialization.Serializer<V> valueSerializer)` Create a new KafkaProducer instance
    `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`.
    `static <K,V> KafkaProducer<K,V>` | `create(Vertx vertx, Properties config)` Create a new KafkaProducer instance
    `static <K,V> KafkaProducer<K,V>` | `create(Vertx vertx, Properties config, Class<K> keyType, Class<V> valueType)` Create a new KafkaProducer instance
    `static <K,V> KafkaProducer<K,V>` | `create(Vertx vertx, Properties config, org.apache.kafka.common.serialization.Serializer<K> keySerializer, org.apache.kafka.common.serialization.Serializer<V> valueSerializer)` Create a new KafkaProducer instance
    `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`
    `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`
    `static <K,V> KafkaProducer<K,V>` | `createShared(Vertx vertx, String name, KafkaClientOptions options, org.apache.kafka.common.serialization.Serializer<K> keySerializer, org.apache.kafka.common.serialization.Serializer<V> valueSerializer)` Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same `name`
    `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`
    `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`
    `static <K,V> KafkaProducer<K,V>` | `createShared(Vertx vertx, String name, Map<String,String> config, org.apache.kafka.common.serialization.Serializer<K> keySerializer, org.apache.kafka.common.serialization.Serializer<V> valueSerializer)` Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same `name`
    `static <K,V> KafkaProducer<K,V>` | `createShared(Vertx vertx, String name, Properties config)` Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same `name`
    `static <K,V> KafkaProducer<K,V>` | `createShared(Vertx vertx, String name, Properties 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`
    `static <K,V> KafkaProducer<K,V>` | `createShared(Vertx vertx, String name, Properties config, org.apache.kafka.common.serialization.Serializer<K> keySerializer, org.apache.kafka.common.serialization.Serializer<V> valueSerializer)` Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same `name`
    `KafkaProducer<K,V>` | `drainHandler(Handler<Void> handler)` Set a drain handler on the stream.
    `KafkaProducer<K,V>` | `exceptionHandler(Handler<Throwable> handler)` Set an exception handler on the write stream.
    `Future<Void>` | `flush()` Like `flush(Handler)` but returns a `Future` of the asynchronous result
    `KafkaProducer<K,V>` | `flush(Handler<AsyncResult<Void>> completionHandler)` Invoking this method makes all buffered records immediately available to write
    `Future<Void>` | `initTransactions()` Like `initTransactions(Handler)` but with a future of the result
    `KafkaProducer<K,V>` | `initTransactions(Handler<AsyncResult<Void>> handler)` Initializes the underlying kafka transactional producer.
    `Future<List<PartitionInfo>>` | `partitionsFor(String topic)` Like `partitionsFor(String, Handler)` but returns a `Future` of the asynchronous result
    `KafkaProducer<K,V>` | `partitionsFor(String topic, Handler<AsyncResult<List<PartitionInfo>>> handler)` Get the partition metadata for the give topic.
    `Future<RecordMetadata>` | `send(KafkaProducerRecord<K,V> record)` Asynchronously write a record to a topic
    `KafkaProducer<K,V>` | `send(KafkaProducerRecord<K,V> record, Handler<AsyncResult<RecordMetadata>> handler)` Asynchronously write a record to a topic
    `KafkaProducer<K,V>` | `setWriteQueueMaxSize(int i)` Set the maximum size of the write queue to `maxSize`.
    `org.apache.kafka.clients.producer.Producer<K,V>` | `unwrap()`

    - ### Methods inherited from interface io.vertx.core.streams.WriteStream

      `end, end, end, end, write, write, writeQueueFull`

- - ### Method Detail

    - #### createShared

          static <K,V> KafkaProducer<K,V> createShared(Vertx vertx,
                                                       String name,
                                                       Properties config)

      Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same `name`
      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

          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`
      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

          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`
      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

          static <K,V> KafkaProducer<K,V> createShared(Vertx vertx,
                                                       String name,
                                                       Map<String,String> config,
                                                       org.apache.kafka.common.serialization.Serializer<K> keySerializer,
                                                       org.apache.kafka.common.serialization.Serializer<V> valueSerializer)

      Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same `name`
      Parameters:
        `vertx` - Vert.x instance to use
        `name` - the producer name to identify it
        `config` - Kafka producer configuration
        `keySerializer` - key serializer
        `valueSerializer` - value serializer
      Returns:
        an instance of the KafkaProducer

    - #### createShared

          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`
      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

          static <K,V> KafkaProducer<K,V> createShared(Vertx vertx,
                                                       String name,
                                                       Properties config,
                                                       org.apache.kafka.common.serialization.Serializer<K> keySerializer,
                                                       org.apache.kafka.common.serialization.Serializer<V> valueSerializer)

      Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same `name`
      Parameters:
        `vertx` - Vert.x instance to use
        `name` - the producer name to identify it
        `config` - Kafka producer configuration
        `keySerializer` - key serializer
        `valueSerializer` - value serializer
      Returns:
        an instance of the KafkaProducer

    - #### createShared

          static <K,V> KafkaProducer<K,V> createShared(Vertx vertx,
                                                       String name,
                                                       Properties 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`
      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

          static <K,V> KafkaProducer<K,V> createShared(Vertx vertx,
                                                       String name,
                                                       KafkaClientOptions options,
                                                       org.apache.kafka.common.serialization.Serializer<K> keySerializer,
                                                       org.apache.kafka.common.serialization.Serializer<V> valueSerializer)

      Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same `name`
      Parameters:
        `vertx` - Vert.x instance to use
        `name` - the producer name to identify it
        `options` - Kafka producer options
        `keySerializer` - key serializer
        `valueSerializer` - value serializer
      Returns:
        an instance of the KafkaProducer

    - #### createShared

          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`
      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

          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

          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

          static <K,V> KafkaProducer<K,V> create(Vertx vertx,
                                                 Map<String,String> config,
                                                 org.apache.kafka.common.serialization.Serializer<K> keySerializer,
                                                 org.apache.kafka.common.serialization.Serializer<V> valueSerializer)

      Create a new KafkaProducer instance
      Parameters:
        `vertx` - Vert.x instance to use
        `config` - Kafka producer configuration
        `keySerializer` - key serializer
        `valueSerializer` - value serializer
      Returns:
        an instance of the KafkaProducer

    - #### create

          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

    - #### create

          static <K,V> KafkaProducer<K,V> create(Vertx vertx,
                                                 Properties config)

      Create a new KafkaProducer instance
      Parameters:
        `vertx` - Vert.x instance to use
        `config` - Kafka producer configuration
      Returns:
        an instance of the KafkaProducer

    - #### create

          static <K,V> KafkaProducer<K,V> create(Vertx vertx,
                                                 Properties config,
                                                 org.apache.kafka.common.serialization.Serializer<K> keySerializer,
                                                 org.apache.kafka.common.serialization.Serializer<V> valueSerializer)

      Create a new KafkaProducer instance
      Parameters:
        `vertx` - Vert.x instance to use
        `config` - Kafka producer configuration
        `keySerializer` - key serializer
        `valueSerializer` - value serializer
      Returns:
        an instance of the KafkaProducer

    - #### create

          static <K,V> KafkaProducer<K,V> create(Vertx vertx,
                                                 Properties 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

          KafkaProducer<K,V> initTransactions(Handler<AsyncResult<Void>> handler)

      Initializes the underlying kafka transactional producer. See `initTransactions()` ()}
      Parameters:
        `handler` - handler called on operation completed
      Returns:
        current KafkaWriteStream instance

    - #### initTransactions

          Future<Void> initTransactions()

      Like `initTransactions(Handler)` but with a future of the result

    - #### beginTransaction

          KafkaProducer<K,V> beginTransaction(Handler<AsyncResult<Void>> handler)

      Starts a new kafka transaction. See `beginTransaction()`
      Parameters:
        `handler` - handler called on operation completed
      Returns:
        current KafkaWriteStream instance

    - #### beginTransaction

          Future<Void> beginTransaction()

      Like `beginTransaction(Handler)` but with a future of the result

    - #### commitTransaction

          KafkaProducer<K,V> commitTransaction(Handler<AsyncResult<Void>> handler)

      Commits the ongoing transaction. See `commitTransaction()`
      Parameters:
        `handler` - handler called on operation completed
      Returns:
        current KafkaWriteStream instance

    - #### commitTransaction

          Future<Void> commitTransaction()

      Like `commitTransaction(Handler)` but with a future of the result

    - #### abortTransaction

          KafkaProducer<K,V> abortTransaction(Handler<AsyncResult<Void>> handler)

      Aborts the ongoing transaction. See `KafkaProducer.abortTransaction()`
      Parameters:
        `handler` - handler called on operation completed
      Returns:
        current KafkaWriteStream instance

    - #### abortTransaction

          Future<Void> abortTransaction()

      Like `abortTransaction(Handler)` but with a future of the result

    - #### exceptionHandler

          KafkaProducer<K,V> exceptionHandler(Handler<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<KafkaProducerRecord<K,V>>`
      Parameters:
        `handler` - the exception handler
      Returns:
        a reference to this, so the API can be used fluently

    - #### setWriteQueueMaxSize

          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<KafkaProducerRecord<K,V>>`
      Parameters:
        `i` - the max size of the write stream
      Returns:
        a reference to this, so the API can be used fluently

    - #### drainHandler

          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<KafkaProducerRecord<K,V>>`
      Parameters:
        `handler` - the handler
      Returns:
        a reference to this, so the API can be used fluently

    - #### send

          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

    - #### send

          KafkaProducer<K,V> send(KafkaProducerRecord<K,V> record,
                                  Handler<AsyncResult<RecordMetadata>> handler)

      Asynchronously write a record to a topic
      Parameters:
        `record` - record to write
        `handler` - handler called on operation completed
      Returns:
        current KafkaWriteStream instance

    - #### partitionsFor

          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

          Future<List<PartitionInfo>> partitionsFor(String topic)

      Like `partitionsFor(String, Handler)` but returns a `Future` of the asynchronous result

    - #### flush

          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

          Future<Void> flush()

      Like `flush(Handler)` but returns a `Future` of the asynchronous result

    - #### close

          Future<Void> close()

      Close the producer
      Returns:
        a `Future` completed with the operation result

    - #### close

          void close(Handler<AsyncResult<Void>> completionHandler)

      Close the producer
      Parameters:
        `completionHandler` - handler called on operation completed

    - #### close

          Future<Void> close(long timeout)

      Like `close(long, Handler)` but returns a `Future` of the asynchronous result

    - #### close

          void close(long timeout,
                     Handler<AsyncResult<Void>> completionHandler)

      Close the producer
      Parameters:
        `timeout` - timeout to wait for closing
        `completionHandler` - handler called on operation completed

    - #### asStream

          KafkaWriteStream<K,V> asStream()

      Returns:
        underlying `KafkaWriteStream` instance

    - #### unwrap

          org.apache.kafka.clients.producer.Producer<K,V> unwrap()

      Returns:
        the underlying producer

Copyright © 2021 Eclipse. All rights reserved.