Class ProduceContext<K,V>

java.lang.Object
io.streamnative.kafka.client.api.ProduceContext<K,V>

public class ProduceContext<K,V> extends Object
Context for producing messages.
  • Constructor Details

    • ProduceContext

      public ProduceContext()
  • Method Details

    • createV2ProducerRecord

      public <T, HeaderT> T createV2ProducerRecord(Class<T> clazz, BiFunction<String,byte[],HeaderT> headerConstructor)
      Create an instance of Kafka's ProducerRecord for kafka version higher than or equal to 0.11.x.
      Type Parameters:
      T - it should be org.apache.kafka.clients.producer.ProducerRecord
      HeaderT - it should be an implementation of org.apache.kafka.common.header.Header, e.g. RecordHeader
      Parameters:
      clazz - the class type of Kafka's ProducerRecord
      headerConstructor - the constructor of Kafka's Header implementation
      Returns:
      an instance of org.apache.kafka.clients.producer.ProducerRecord
    • createV1ProducerRecord

      public <T> T createV1ProducerRecord(Class<T> clazz)
      Create an instance of Kafka's ProducerRecord less than 0.11.x. Because there is no header in ProducerRecord before 0.11.x.
      Type Parameters:
      T - it should be org.apache.kafka.clients.producer.ProducerRecord
      Parameters:
      clazz - the class type of Kafka's ProducerRecord
      Returns:
      an instance of org.apache.kafka.clients.producer.ProducerRecord
    • createV0ProducerRecord

      public <T> T createV0ProducerRecord(Class<T> clazz)
      Create an instance of Kafka's ProducerRecord less than 0.10.x. Because there is no timestamp in ProducerRecord before 0.10.x.
      Type Parameters:
      T - it should be org.apache.kafka.clients.producer.ProducerRecord
      Parameters:
      clazz - the class type of Kafka's ProducerRecord
      Returns:
      an instance of org.apache.kafka.clients.producer.ProducerRecord
    • complete

      public <T> void complete(T metadata, Exception e)
      Complete the internal `future` field.
      Type Parameters:
      T - it should be org.apache.kafka.clients.producer.RecordMetadata
      Parameters:
      metadata - the instance of Kafka's RecordMetadata
      e - the exception to complete exceptionally if it's not null
    • sendAsync

      public Future<RecordMetadata> sendAsync()
      Send the message using ProduceContext instead of using Producer directly.
      See Also:
    • builder

      public static <K, V> ProduceContext.ProduceContextBuilder<K,V> builder()