io.vertx.kafka.client.producer

## Interface KafkaWriteStream<K,V>

- All Superinterfaces:
    StreamBase, WriteStream<org.apache.kafka.clients.producer.ProducerRecord<K,V>>

      public interface KafkaWriteStream<K,V>
      extends WriteStream<org.apache.kafka.clients.producer.ProducerRecord<K,V>>

  A `WriteStream` for writing to Kafka `ProducerRecord`.

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

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `DEFAULT_MAX_SIZE`

  - ### 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
    `KafkaWriteStream<K,V>` | `abortTransaction(Handler<AsyncResult<Void>> handler)` Aborts the ongoing transaction.
    `Future<Void>` | `beginTransaction()` Like `beginTransaction(Handler)` but with a future of the result
    `KafkaWriteStream<K,V>` | `beginTransaction(Handler<AsyncResult<Void>> handler)` Starts a new kafka transaction.
    `Future<Void>` | `close()` Close the stream
    `void` | `close(Handler<AsyncResult<Void>> completionHandler)` Close the stream
    `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 stream
    `Future<Void>` | `commitTransaction()` Like `commitTransaction(Handler)` but with a future of the result
    `KafkaWriteStream<K,V>` | `commitTransaction(Handler<AsyncResult<Void>> handler)` Commits the ongoing transaction.
    `static <K,V> KafkaWriteStream<K,V>` | `create(Vertx vertx, KafkaClientOptions options)` Create a new KafkaWriteStream instance
    `static <K,V> KafkaWriteStream<K,V>` | `create(Vertx vertx, KafkaClientOptions options, Class<K> keyType, Class<V> valueType)` Create a new KafkaWriteStream instance
    `static <K,V> KafkaWriteStream<K,V>` | `create(Vertx vertx, KafkaClientOptions options, org.apache.kafka.common.serialization.Serializer<K> keySerializer, org.apache.kafka.common.serialization.Serializer<V> valueSerializer)` Create a new KafkaWriteStream instance
    `static <K,V> KafkaWriteStream<K,V>` | `create(Vertx vertx, Map<String,Object> config)` Create a new KafkaWriteStream instance
    `static <K,V> KafkaWriteStream<K,V>` | `create(Vertx vertx, Map<String,Object> config, Class<K> keyType, Class<V> valueType)` Create a new KafkaWriteStream instance
    `static <K,V> KafkaWriteStream<K,V>` | `create(Vertx vertx, Map<String,Object> config, org.apache.kafka.common.serialization.Serializer<K> keySerializer, org.apache.kafka.common.serialization.Serializer<V> valueSerializer)` Create a new KafkaWriteStream instance
    `static <K,V> KafkaWriteStream<K,V>` | `create(Vertx vertx, org.apache.kafka.clients.producer.Producer<K,V> producer)` Create a new KafkaWriteStream instance
    `static <K,V> KafkaWriteStream<K,V>` | `create(Vertx vertx, Properties config)` Create a new KafkaWriteStream instance
    `static <K,V> KafkaWriteStream<K,V>` | `create(Vertx vertx, Properties config, Class<K> keyType, Class<V> valueType)` Create a new KafkaWriteStream instance
    `static <K,V> KafkaWriteStream<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 KafkaWriteStream instance
    `KafkaWriteStream<K,V>` | `drainHandler(Handler<Void> handler)` Set a drain handler on the stream.
    `KafkaWriteStream<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
    `KafkaWriteStream<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
    `KafkaWriteStream<K,V>` | `initTransactions(Handler<AsyncResult<Void>> handler)` Initializes the underlying kafka transactional producer.
    `Future<List<org.apache.kafka.common.PartitionInfo>>` | `partitionsFor(String topic)` Like `partitionsFor(String, Handler)` but returns a `Future` of the asynchronous result
    `KafkaWriteStream<K,V>` | `partitionsFor(String topic, Handler<AsyncResult<List<org.apache.kafka.common.PartitionInfo>>> handler)` Get the partition metadata for the give topic.
    `Future<org.apache.kafka.clients.producer.RecordMetadata>` | `send(org.apache.kafka.clients.producer.ProducerRecord<K,V> record)` Asynchronously write a record to a topic
    `KafkaWriteStream<K,V>` | `send(org.apache.kafka.clients.producer.ProducerRecord<K,V> record, Handler<AsyncResult<org.apache.kafka.clients.producer.RecordMetadata>> handler)` Asynchronously write a record to a topic
    `KafkaWriteStream<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`

- - ### Field Detail

    - #### DEFAULT_MAX_SIZE

          static final int DEFAULT_MAX_SIZE

      See Also:
        Constant Field Values

  - ### Method Detail

    - #### create

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

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

    - #### create

          static <K,V> KafkaWriteStream<K,V> create(Vertx vertx,
                                                    Properties config,
                                                    Class<K> keyType,
                                                    Class<V> valueType)

      Create a new KafkaWriteStream 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 KafkaWriteStream

    - #### create

          static <K,V> KafkaWriteStream<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 KafkaWriteStream instance
      Parameters:
        `vertx` - Vert.x instance to use
        `config` - Kafka producer configuration
        `keySerializer` - key serializer
        `valueSerializer` - value serializer
      Returns:
        an instance of the KafkaWriteStream

    - #### create

          static <K,V> KafkaWriteStream<K,V> create(Vertx vertx,
                                                    Map<String,Object> config)

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

    - #### create

          static <K,V> KafkaWriteStream<K,V> create(Vertx vertx,
                                                    Map<String,Object> config,
                                                    Class<K> keyType,
                                                    Class<V> valueType)

      Create a new KafkaWriteStream 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 KafkaWriteStream

    - #### create

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

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

    - #### create

          static <K,V> KafkaWriteStream<K,V> create(Vertx vertx,
                                                    KafkaClientOptions options)

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

    - #### create

          static <K,V> KafkaWriteStream<K,V> create(Vertx vertx,
                                                    KafkaClientOptions options,
                                                    Class<K> keyType,
                                                    Class<V> valueType)

      Create a new KafkaWriteStream instance
      Parameters:
        `vertx` - Vert.x instance to use
        `options` - Kafka producer options
        `keyType` - class type for the key serialization
        `valueType` - class type for the value serialization
      Returns:
        an instance of the KafkaWriteStream

    - #### create

          static <K,V> KafkaWriteStream<K,V> create(Vertx vertx,
                                                    KafkaClientOptions options,
                                                    org.apache.kafka.common.serialization.Serializer<K> keySerializer,
                                                    org.apache.kafka.common.serialization.Serializer<V> valueSerializer)

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

    - #### create

          static <K,V> KafkaWriteStream<K,V> create(Vertx vertx,
                                                    org.apache.kafka.clients.producer.Producer<K,V> producer)

      Create a new KafkaWriteStream instance
      Parameters:
        `vertx` - Vert.x instance to use
        `producer` - native Kafka producer instance

    - #### exceptionHandler

          KafkaWriteStream<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<org.apache.kafka.clients.producer.ProducerRecord<K,V>>`
      Parameters:
        `handler` - the exception handler
      Returns:
        a reference to this, so the API can be used fluently

    - #### setWriteQueueMaxSize

          KafkaWriteStream<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<org.apache.kafka.clients.producer.ProducerRecord<K,V>>`
      Parameters:
        `i` - the max size of the write stream
      Returns:
        a reference to this, so the API can be used fluently

    - #### drainHandler

          KafkaWriteStream<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<org.apache.kafka.clients.producer.ProducerRecord<K,V>>`
      Parameters:
        `handler` - the handler
      Returns:
        a reference to this, so the API can be used fluently

    - #### initTransactions

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

      Initializes the underlying kafka transactional producer. See `KafkaProducer.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

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

      Starts a new kafka transaction. See `KafkaProducer.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

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

      Commits the ongoing transaction. See `KafkaProducer.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

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

    - #### send

          Future<org.apache.kafka.clients.producer.RecordMetadata> send(org.apache.kafka.clients.producer.ProducerRecord<K,V> record)

      Asynchronously write a record to a topic
      Parameters:
        `record` - record to write
      Returns:
        a `Future` completed with the record metadata

    - #### send

          KafkaWriteStream<K,V> send(org.apache.kafka.clients.producer.ProducerRecord<K,V> record,
                                     Handler<AsyncResult<org.apache.kafka.clients.producer.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

          KafkaWriteStream<K,V> partitionsFor(String topic,
                                              Handler<AsyncResult<List<org.apache.kafka.common.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 KafkaWriteStream instance

    - #### partitionsFor

          Future<List<org.apache.kafka.common.PartitionInfo>> partitionsFor(String topic)

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

    - #### flush

          KafkaWriteStream<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 KafkaWriteStream instance

    - #### flush

          Future<Void> flush()

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

    - #### close

          Future<Void> close()

      Close the stream

    - #### close

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

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

    - #### close

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

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

    - #### close

          Future<Void> close(long timeout)

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

    - #### unwrap

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

      Returns:
        the underlying producer

Copyright © 2023 Eclipse. All rights reserved.