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 -
Method Summary
Modifier and TypeMethodDescriptionAborts the ongoing transaction.Starts a new kafka transaction.close()Close the streamclose(long timeout) Close the streamCommits the ongoing transaction.static <K,V> KafkaWriteStream <K, V> create(Vertx vertx, KafkaClientOptions options) Create a new KafkaWriteStream instancestatic <K,V> KafkaWriteStream <K, V> create(Vertx vertx, KafkaClientOptions options, Class<K> keyType, Class<V> valueType) Create a new KafkaWriteStream instancestatic <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 instancestatic <K,V> KafkaWriteStream <K, V> Create a new KafkaWriteStream instancestatic <K,V> KafkaWriteStream <K, V> Create a new KafkaWriteStream instancestatic <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 instancestatic <K,V> KafkaWriteStream <K, V> create(Vertx vertx, Properties config) Create a new KafkaWriteStream instancestatic <K,V> KafkaWriteStream <K, V> create(Vertx vertx, Properties config, Class<K> keyType, Class<V> valueType) Create a new KafkaWriteStream instancestatic <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 instancestatic <K,V> KafkaWriteStream <K, V> Create a new KafkaWriteStream instancestatic <K,V> KafkaWriteStream <K, V> create(Vertx vertx, org.apache.kafka.clients.producer.Producer<K, V> producer, KafkaClientOptions options) Create a new KafkaWriteStream instance.drainHandler(Handler<Void> handler) Set a drain handler on the stream.exceptionHandler(Handler<Throwable> handler) Set an exception handler on the write stream.flush()Invoking this method makes all buffered records immediately available to writeInitializes the underlying kafka transactional producer.partitionsFor(String topic) Get the partition metadata for the give topic.Future<org.apache.kafka.clients.producer.RecordMetadata> Asynchronously write a record to a topicsetWriteQueueMaxSize(int i) Set the maximum size of the write queue tomaxSize.unwrap()Methods inherited from interface WriteStream
end, end, write, writeQueueFull
-
Field Details
-
DEFAULT_MAX_SIZE
static final int DEFAULT_MAX_SIZE- See Also:
-
-
Method Details
-
create
Create a new KafkaWriteStream instance- Parameters:
vertx- Vert.x instance to useconfig- 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 useconfig- Kafka producer configurationkeyType- class type for the key serializationvalueType- 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 useconfig- Kafka producer configurationkeySerializer- key serializervalueSerializer- value serializer- Returns:
- an instance of the KafkaWriteStream
-
create
Create a new KafkaWriteStream instance- Parameters:
vertx- Vert.x instance to useconfig- 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 useconfig- Kafka producer configurationkeyType- class type for the key serializationvalueType- 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 useconfig- Kafka producer configurationkeySerializer- key serializervalueSerializer- value serializer- Returns:
- an instance of the KafkaWriteStream
-
create
Create a new KafkaWriteStream instance- Parameters:
vertx- Vert.x instance to useoptions- 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 useoptions- Kafka producer optionskeyType- class type for the key serializationvalueType- 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 useoptions- Kafka producer optionskeySerializer- key serializervalueSerializer- 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 useproducer- native Kafka producer instance
-
create
static <K,V> KafkaWriteStream<K,V> create(Vertx vertx, org.apache.kafka.clients.producer.Producer<K, V> producer, KafkaClientOptions options) Create a new KafkaWriteStream instance.- Parameters:
vertx- Vert.x instance to useproducer- native Kafka producer instanceoptions- options used only for tracing settings
-
exceptionHandler
Description copied from interface:WriteStreamSet an exception handler on the write stream.- Specified by:
exceptionHandlerin interfaceStreamBase- Specified by:
exceptionHandlerin interfaceWriteStream<K>- Parameters:
handler- the exception handler- Returns:
- a reference to this, so the API can be used fluently
-
setWriteQueueMaxSize
Description copied from interface:WriteStreamSet the maximum size of the write queue tomaxSize. You will still be able to write to the stream even if there is more thanmaxSizeitems in the write queue. This is used as an indicator by classes such asPipeto provide flow control. The value is defined by the implementation of the stream, e.g in bytes for aNetSocket, etc...- Specified by:
setWriteQueueMaxSizein interfaceWriteStream<K>- Parameters:
i- the max size of the write stream- Returns:
- a reference to this, so the API can be used fluently
-
drainHandler
Description copied from interface:WriteStreamSet 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. SeePipefor 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:
drainHandlerin interfaceWriteStream<K>- Parameters:
handler- the handler- Returns:
- a reference to this, so the API can be used fluently
-
initTransactions
Initializes the underlying kafka transactional producer. SeeKafkaProducer.initTransactions()()}- Returns:
- a future notified with the result
-
beginTransaction
Starts a new kafka transaction. SeeKafkaProducer.beginTransaction()- Returns:
- a future notified with the result
-
commitTransaction
Commits the ongoing transaction. SeeKafkaProducer.commitTransaction()- Returns:
- a future notified with the result
-
abortTransaction
-
send
-
partitionsFor
-
flush
-
close
-
close
-
unwrap
-