Package io.streamnative.kafka.client.api
Class ProduceContext<K,V>
java.lang.Object
io.streamnative.kafka.client.api.ProduceContext<K,V>
Context for producing messages.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <K,V> ProduceContext.ProduceContextBuilder<K, V> builder()<T> voidComplete the internal `future` field.<T> TcreateV0ProducerRecord(Class<T> clazz) Create an instance of Kafka's ProducerRecord less than 0.10.x.<T> TcreateV1ProducerRecord(Class<T> clazz) Create an instance of Kafka's ProducerRecord less than 0.11.x.<T,HeaderT>
TcreateV2ProducerRecord(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.Send the message using ProduceContext instead of using Producer directly.
-
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.ProducerRecordHeaderT- it should be an implementation of org.apache.kafka.common.header.Header, e.g. RecordHeader- Parameters:
clazz- the class type of Kafka's ProducerRecordheaderConstructor- the constructor of Kafka's Header implementation- Returns:
- an instance of org.apache.kafka.clients.producer.ProducerRecord
-
createV1ProducerRecord
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
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
Complete the internal `future` field.- Type Parameters:
T- it should be org.apache.kafka.clients.producer.RecordMetadata- Parameters:
metadata- the instance of Kafka's RecordMetadatae- the exception to complete exceptionally if it's not null
-
sendAsync
Send the message using ProduceContext instead of using Producer directly.- See Also:
-
builder
-