Class KafkaProducer<K,V>
- java.lang.Object
-
- io.vertx.rxjava.kafka.client.producer.KafkaProducer<K,V>
-
- All Implemented Interfaces:
StreamBase,WriteStream<KafkaProducerRecord<K,V>>
public class KafkaProducer<K,V> extends Object implements WriteStream<KafkaProducerRecord<K,V>>
Vert.x Kafka producer.The
NOTE: This class has been automatically generated from theWriteStream.write(T, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)provides global control over writing a record.originalnon RX-ified interface using Vert.x codegen.
-
-
Field Summary
Fields Modifier and Type Field Description static TypeArg<KafkaProducer>__TYPE_ARGTypeArg<K>__typeArg_0TypeArg<V>__typeArg_1
-
Constructor Summary
Constructors Constructor Description KafkaProducer(KafkaProducer delegate)KafkaProducer(Object delegate, TypeArg<K> typeArg_0, TypeArg<V> typeArg_1)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description KafkaProducer<K,V>abortTransaction()Aborts the ongoing transaction.KafkaProducer<K,V>abortTransaction(Handler<AsyncResult<Void>> handler)Aborts the ongoing transaction.KafkaProducer<K,V>beginTransaction()Starts a new kafka transaction.KafkaProducer<K,V>beginTransaction(Handler<AsyncResult<Void>> handler)Starts a new kafka transaction.voidclose()Close the producervoidclose(long timeout)Close the producervoidclose(long timeout, Handler<AsyncResult<Void>> completionHandler)Close the producervoidclose(Handler<AsyncResult<Void>> completionHandler)Close the producerKafkaProducer<K,V>commitTransaction()Commits the ongoing transaction.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 instancestatic <K,V>
KafkaProducer<K,V>create(Vertx vertx, Map<String,String> config, Class<K> keyType, Class<V> valueType)Create a new KafkaProducer instancestatic <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 samenamestatic <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 samenamestatic <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 samenamestatic <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 samenameKafkaProducer<K,V>drainHandler(Handler<Void> handler)Set a drain handler on the stream.voidend()Same asWriteStream.end(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)but with anhandlercalled when the operation completesvoidend(Handler<AsyncResult<Void>> handler)Same asWriteStream.end(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)but with anhandlercalled when the operation completesvoidend(KafkaProducerRecord<K,V> data)Same as but with anhandlercalled when the operation completesvoidend(KafkaProducerRecord<K,V> data, Handler<AsyncResult<Void>> handler)Same as but with anhandlercalled when the operation completesbooleanequals(Object o)KafkaProducer<K,V>exceptionHandler(Handler<Throwable> handler)Set an exception handler on the write stream.KafkaProducer<K,V>flush()Invoking this method makes all buffered records immediately available to writeKafkaProducer<K,V>flush(Handler<AsyncResult<Void>> completionHandler)Invoking this method makes all buffered records immediately available to writeKafkaProducergetDelegate()inthashCode()KafkaProducer<K,V>initTransactions()Initializes the underlying kafka transactional producer.KafkaProducer<K,V>initTransactions(Handler<AsyncResult<Void>> handler)Initializes the underlying kafka transactional producer.static <K,V>
KafkaProducer<K,V>newInstance(KafkaProducer arg)static <K,V>
KafkaProducer<K,V>newInstance(KafkaProducer arg, TypeArg<K> __typeArg_K, TypeArg<V> __typeArg_V)KafkaProducer<K,V>partitionsFor(String topic)Get the partition metadata for the give topic.KafkaProducer<K,V>partitionsFor(String topic, Handler<AsyncResult<List<PartitionInfo>>> handler)Get the partition metadata for the give topic.rx.Single<Void>rxAbortTransaction()Aborts the ongoing transaction.rx.Single<Void>rxBeginTransaction()Starts a new kafka transaction.rx.Single<Void>rxClose()Close the producerrx.Single<Void>rxClose(long timeout)Close the producerrx.Single<Void>rxCommitTransaction()Commits the ongoing transaction.rx.Single<Void>rxEnd()Same asWriteStream.end(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)but with anhandlercalled when the operation completesrx.Single<Void>rxEnd(KafkaProducerRecord<K,V> data)Same as but with anhandlercalled when the operation completesrx.Single<Void>rxFlush()Invoking this method makes all buffered records immediately available to writerx.Single<Void>rxInitTransactions()Initializes the underlying kafka transactional producer.rx.Single<List<PartitionInfo>>rxPartitionsFor(String topic)Get the partition metadata for the give topic.rx.Single<RecordMetadata>rxSend(KafkaProducerRecord<K,V> record)Asynchronously write a record to a topicrx.Single<Void>rxWrite(KafkaProducerRecord<K,V> data)Same as but with anhandlercalled when the operation completesKafkaProducer<K,V>send(KafkaProducerRecord<K,V> record)Asynchronously write a record to a topicKafkaProducer<K,V>send(KafkaProducerRecord<K,V> record, Handler<AsyncResult<RecordMetadata>> handler)Asynchronously write a record to a topicKafkaProducer<K,V>setWriteQueueMaxSize(int i)Set the maximum size of the write queue tomaxSize.StringtoString()WriteStreamSubscriber<KafkaProducerRecord<K,V>>toSubscriber()voidwrite(KafkaProducerRecord<K,V> data)Same as but with anhandlercalled when the operation completesvoidwrite(KafkaProducerRecord<K,V> data, Handler<AsyncResult<Void>> handler)Same as but with anhandlercalled when the operation completesbooleanwriteQueueFull()This will returntrueif there are more bytes in the write queue than the value set usingsetWriteQueueMaxSize(int)
-
-
-
Method Detail
-
getDelegate
public KafkaProducer getDelegate()
- Specified by:
getDelegatein interfaceStreamBase- Specified by:
getDelegatein interfaceWriteStream<K>
-
toSubscriber
public WriteStreamSubscriber<KafkaProducerRecord<K,V>> toSubscriber()
-
write
public void write(KafkaProducerRecord<K,V> data, Handler<AsyncResult<Void>> handler)
Same as but with anhandlercalled when the operation completes- Specified by:
writein interfaceWriteStream<K>- Parameters:
data-handler-
-
write
public void write(KafkaProducerRecord<K,V> data)
Same as but with anhandlercalled when the operation completes- Specified by:
writein interfaceWriteStream<K>- Parameters:
data-
-
rxWrite
public rx.Single<Void> rxWrite(KafkaProducerRecord<K,V> data)
Same as but with anhandlercalled when the operation completes- Specified by:
rxWritein interfaceWriteStream<K>- Parameters:
data-- Returns:
-
end
public void end(Handler<AsyncResult<Void>> handler)
Same asWriteStream.end(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)but with anhandlercalled when the operation completes- Specified by:
endin interfaceWriteStream<K>- Parameters:
handler-
-
end
public void end()
Same asWriteStream.end(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)but with anhandlercalled when the operation completes- Specified by:
endin interfaceWriteStream<K>
-
rxEnd
public rx.Single<Void> rxEnd()
Same asWriteStream.end(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)but with anhandlercalled when the operation completes- Specified by:
rxEndin interfaceWriteStream<K>- Returns:
-
end
public void end(KafkaProducerRecord<K,V> data, Handler<AsyncResult<Void>> handler)
Same as but with anhandlercalled when the operation completes- Specified by:
endin interfaceWriteStream<K>- Parameters:
data-handler-
-
end
public void end(KafkaProducerRecord<K,V> data)
Same as but with anhandlercalled when the operation completes- Specified by:
endin interfaceWriteStream<K>- Parameters:
data-
-
rxEnd
public rx.Single<Void> rxEnd(KafkaProducerRecord<K,V> data)
Same as but with anhandlercalled when the operation completes- Specified by:
rxEndin interfaceWriteStream<K>- Parameters:
data-- Returns:
-
writeQueueFull
public boolean writeQueueFull()
This will returntrueif there are more bytes in the write queue than the value set usingsetWriteQueueMaxSize(int)- Specified by:
writeQueueFullin interfaceWriteStream<K>- Returns:
trueif write queue is full
-
createShared
public 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 samenameWhen
closehas been called for each shared producer the resources will be released. Callingendcloses all shared producers.- Parameters:
vertx- Vert.x instance to usename- the producer name to identify itconfig- Kafka producer configuration- Returns:
- an instance of the KafkaProducer
-
createShared
public 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 samenameWhen
closehas been called for each shared producer the resources will be released. Callingendcloses all shared producers.- Parameters:
vertx- Vert.x instance to usename- the producer name to identify itoptions- Kafka producer options- Returns:
- an instance of the KafkaProducer
-
createShared
public 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 samenameWhen
closehas been called for each shared producer the resources will be released. Callingendcloses all shared producers.- Parameters:
vertx- Vert.x instance to usename- the producer name to identify itconfig- Kafka producer configurationkeyType- class type for the key serializationvalueType- class type for the value serialization- Returns:
- an instance of the KafkaProducer
-
createShared
public 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 samenameWhen
closehas been called for each shared producer the resources will be released. Callingendcloses all shared producers.- Parameters:
vertx- Vert.x instance to usename- the producer name to identify itoptions- Kafka producer optionskeyType- class type for the key serializationvalueType- class type for the value serialization- Returns:
- an instance of the KafkaProducer
-
create
public static <K,V> KafkaProducer<K,V> create(Vertx vertx, Map<String,String> config)
Create a new KafkaProducer instance- Parameters:
vertx- Vert.x instance to useconfig- Kafka producer configuration- Returns:
- an instance of the KafkaProducer
-
create
public 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 useconfig- Kafka producer configurationkeyType- class type for the key serializationvalueType- class type for the value serialization- Returns:
- an instance of the KafkaProducer
-
initTransactions
public KafkaProducer<K,V> initTransactions(Handler<AsyncResult<Void>> handler)
Initializes the underlying kafka transactional producer. SeeinitTransactions(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)()}- Parameters:
handler- handler called on operation completed- Returns:
- current KafkaWriteStream instance
-
initTransactions
public KafkaProducer<K,V> initTransactions()
Initializes the underlying kafka transactional producer. SeeinitTransactions(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)()}- Returns:
- current KafkaWriteStream instance
-
rxInitTransactions
public rx.Single<Void> rxInitTransactions()
Initializes the underlying kafka transactional producer. SeeinitTransactions(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)()}- Returns:
- current KafkaWriteStream instance
-
beginTransaction
public KafkaProducer<K,V> beginTransaction(Handler<AsyncResult<Void>> handler)
Starts a new kafka transaction. SeebeginTransaction(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)- Parameters:
handler- handler called on operation completed- Returns:
- current KafkaWriteStream instance
-
beginTransaction
public KafkaProducer<K,V> beginTransaction()
Starts a new kafka transaction. SeebeginTransaction(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)- Returns:
- current KafkaWriteStream instance
-
rxBeginTransaction
public rx.Single<Void> rxBeginTransaction()
Starts a new kafka transaction. SeebeginTransaction(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)- Returns:
- current KafkaWriteStream instance
-
commitTransaction
public KafkaProducer<K,V> commitTransaction(Handler<AsyncResult<Void>> handler)
Commits the ongoing transaction. SeecommitTransaction(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)- Parameters:
handler- handler called on operation completed- Returns:
- current KafkaWriteStream instance
-
commitTransaction
public KafkaProducer<K,V> commitTransaction()
Commits the ongoing transaction. SeecommitTransaction(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)- Returns:
- current KafkaWriteStream instance
-
rxCommitTransaction
public rx.Single<Void> rxCommitTransaction()
Commits the ongoing transaction. SeecommitTransaction(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)- Returns:
- current KafkaWriteStream instance
-
abortTransaction
public KafkaProducer<K,V> abortTransaction(Handler<AsyncResult<Void>> handler)
Aborts the ongoing transaction. SeeKafkaProducer- Parameters:
handler- handler called on operation completed- Returns:
- current KafkaWriteStream instance
-
abortTransaction
public KafkaProducer<K,V> abortTransaction()
Aborts the ongoing transaction. SeeKafkaProducer- Returns:
- current KafkaWriteStream instance
-
rxAbortTransaction
public rx.Single<Void> rxAbortTransaction()
Aborts the ongoing transaction. SeeKafkaProducer- Returns:
- current KafkaWriteStream instance
-
exceptionHandler
public KafkaProducer<K,V> exceptionHandler(Handler<Throwable> handler)
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
public KafkaProducer<K,V> setWriteQueueMaxSize(int i)
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
public KafkaProducer<K,V> drainHandler(Handler<Void> handler)
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
-
send
public KafkaProducer<K,V> send(KafkaProducerRecord<K,V> record, Handler<AsyncResult<RecordMetadata>> handler)
Asynchronously write a record to a topic- Parameters:
record- record to writehandler- handler called on operation completed- Returns:
- current KafkaWriteStream instance
-
send
public KafkaProducer<K,V> send(KafkaProducerRecord<K,V> record)
Asynchronously write a record to a topic- Parameters:
record- record to write- Returns:
- current KafkaWriteStream instance
-
rxSend
public rx.Single<RecordMetadata> rxSend(KafkaProducerRecord<K,V> record)
Asynchronously write a record to a topic- Parameters:
record- record to write- Returns:
- current KafkaWriteStream instance
-
partitionsFor
public 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 infohandler- handler called on operation completed- Returns:
- current KafkaProducer instance
-
partitionsFor
public KafkaProducer<K,V> partitionsFor(String topic)
Get the partition metadata for the give topic.- Parameters:
topic- topic partition for which getting partitions info- Returns:
- current KafkaProducer instance
-
rxPartitionsFor
public rx.Single<List<PartitionInfo>> rxPartitionsFor(String topic)
Get the partition metadata for the give topic.- Parameters:
topic- topic partition for which getting partitions info- Returns:
- current KafkaProducer instance
-
flush
public 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
public KafkaProducer<K,V> flush()
Invoking this method makes all buffered records immediately available to write- Returns:
- current KafkaProducer instance
-
rxFlush
public rx.Single<Void> rxFlush()
Invoking this method makes all buffered records immediately available to write- Returns:
- current KafkaProducer instance
-
close
public void close(Handler<AsyncResult<Void>> completionHandler)
Close the producer- Parameters:
completionHandler- handler called on operation completed
-
close
public void close()
Close the producer
-
rxClose
public rx.Single<Void> rxClose()
Close the producer- Returns:
-
close
public void close(long timeout, Handler<AsyncResult<Void>> completionHandler)Close the producer- Parameters:
timeout- timeout to wait for closingcompletionHandler- handler called on operation completed
-
close
public void close(long timeout)
Close the producer- Parameters:
timeout- timeout to wait for closing
-
rxClose
public rx.Single<Void> rxClose(long timeout)
Close the producer- Parameters:
timeout- timeout to wait for closing- Returns:
-
newInstance
public static <K,V> KafkaProducer<K,V> newInstance(KafkaProducer arg)
-
newInstance
public static <K,V> KafkaProducer<K,V> newInstance(KafkaProducer arg, TypeArg<K> __typeArg_K, TypeArg<V> __typeArg_V)
-
-