public class KafkaProducerImpl<K,V> extends Object implements KafkaProducer<K,V>
| Constructor and Description |
|---|
KafkaProducerImpl(KafkaWriteStream<K,V> stream) |
KafkaProducerImpl(KafkaWriteStream<K,V> stream,
CloseHandler closeHandler) |
| Modifier and Type | Method and Description |
|---|---|
KafkaWriteStream<K,V> |
asStream() |
void |
close()
Close the producer
|
void |
close(Handler<AsyncResult<Void>> completionHandler)
Close the producer
|
void |
close(long timeout,
Handler<AsyncResult<Void>> completionHandler)
Close the producer
|
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 same
name |
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 same
name |
static <K,V> KafkaProducer<K,V> |
createShared(Vertx vertx,
String name,
Map<String,String> config,
org.apache.kafka.common.serialization.Serializer<K> keySerializer,
org.apache.kafka.common.serialization.Serializer<V> valueSerializer)
Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same
name |
static <K,V> KafkaProducer<K,V> |
createShared(Vertx vertx,
String name,
Properties config)
Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same
name |
static <K,V> KafkaProducer<K,V> |
createShared(Vertx vertx,
String name,
Properties config,
Class<K> keyType,
Class<V> valueType)
Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same
name |
static <K,V> KafkaProducer<K,V> |
createShared(Vertx vertx,
String name,
Properties config,
org.apache.kafka.common.serialization.Serializer<K> keySerializer,
org.apache.kafka.common.serialization.Serializer<V> valueSerializer)
Get or create a KafkaProducer instance which shares its stream with any other KafkaProducer created with the same
name |
KafkaProducer<K,V> |
drainHandler(Handler<Void> handler)
Set a drain handler on the stream.
|
void |
end()
Ends the stream.
|
void |
end(Handler<AsyncResult<Void>> handler)
Same as
WriteStream.end() but with an handler called when the operation completes |
void |
end(KafkaProducerRecord<K,V> kafkaProducerRecord)
Same as
WriteStream.end() but writes some data to the stream before ending. |
KafkaProducer<K,V> |
exceptionHandler(Handler<Throwable> handler)
Set an exception handler on the write stream.
|
KafkaProducer<K,V> |
flush(Handler<Void> completionHandler)
Invoking this method makes all buffered records immediately available to write
|
KafkaProducer<K,V> |
partitionsFor(String topic,
Handler<AsyncResult<List<PartitionInfo>>> handler)
Get the partition metadata for the give topic.
|
KafkaProducerImpl<K,V> |
registerCloseHook() |
KafkaProducer<K,V> |
send(KafkaProducerRecord<K,V> record)
Asynchronously write a record to a topic
|
KafkaProducer<K,V> |
send(KafkaProducerRecord<K,V> record,
Handler<AsyncResult<RecordMetadata>> handler)
Asynchronously write a record to a topic
|
KafkaProducer<K,V> |
setWriteQueueMaxSize(int size)
Set the maximum size of the write queue to
maxSize. |
org.apache.kafka.clients.producer.Producer<K,V> |
unwrap() |
KafkaProducer<K,V> |
write(KafkaProducerRecord<K,V> kafkaProducerRecord)
Write some data to the stream.
|
KafkaProducer<K,V> |
write(KafkaProducerRecord<K,V> record,
Handler<AsyncResult<Void>> handler)
Same as
#write(T) but with an handler called when the operation completes |
boolean |
writeQueueFull()
This will return
true if there are more bytes in the write queue than the value set using WriteStream.setWriteQueueMaxSize(int) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcreate, create, create, create, create, create, createendpublic KafkaProducerImpl(KafkaWriteStream<K,V> stream, CloseHandler closeHandler)
public KafkaProducerImpl(KafkaWriteStream<K,V> stream)
public static <K,V> KafkaProducer<K,V> createShared(Vertx vertx, String name, Properties config)
KafkaProducernamecreateShared in interface KafkaProducer<K,V>vertx - Vert.x instance to usename - the producer name to identify itconfig - Kafka producer configurationpublic static <K,V> KafkaProducer<K,V> createShared(Vertx vertx, String name, Map<String,String> config)
KafkaProducernamecreateShared in interface KafkaProducer<K,V>vertx - Vert.x instance to usename - the producer name to identify itconfig - Kafka producer configurationpublic static <K,V> KafkaProducer<K,V> createShared(Vertx vertx, String name, Properties config, Class<K> keyType, Class<V> valueType)
KafkaProducernamecreateShared in interface KafkaProducer<K,V>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 serializationpublic static <K,V> KafkaProducer<K,V> createShared(Vertx vertx, String name, Properties config, org.apache.kafka.common.serialization.Serializer<K> keySerializer, org.apache.kafka.common.serialization.Serializer<V> valueSerializer)
KafkaProducernamecreateShared in interface KafkaProducer<K,V>vertx - Vert.x instance to usename - the producer name to identify itconfig - Kafka producer configurationkeySerializer - key serializervalueSerializer - value serializerpublic static <K,V> KafkaProducer<K,V> createShared(Vertx vertx, String name, Map<String,String> config, Class<K> keyType, Class<V> valueType)
KafkaProducernamecreateShared in interface KafkaProducer<K,V>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 serializationpublic static <K,V> KafkaProducer<K,V> createShared(Vertx vertx, String name, Map<String,String> config, org.apache.kafka.common.serialization.Serializer<K> keySerializer, org.apache.kafka.common.serialization.Serializer<V> valueSerializer)
KafkaProducernamecreateShared in interface KafkaProducer<K,V>vertx - Vert.x instance to usename - the producer name to identify itconfig - Kafka producer configurationkeySerializer - key serializervalueSerializer - value serializerpublic KafkaProducerImpl<K,V> registerCloseHook()
public KafkaProducer<K,V> exceptionHandler(Handler<Throwable> handler)
WriteStreamexceptionHandler in interface StreamBaseexceptionHandler in interface WriteStream<KafkaProducerRecord<K,V>>exceptionHandler in interface KafkaProducer<K,V>handler - the exception handlerpublic KafkaProducer<K,V> write(KafkaProducerRecord<K,V> kafkaProducerRecord)
WriteStreamWriteStream.writeQueueFull() method before writing. This is done automatically if using a Pump.write in interface WriteStream<KafkaProducerRecord<K,V>>write in interface KafkaProducer<K,V>kafkaProducerRecord - the data to writepublic KafkaProducer<K,V> write(KafkaProducerRecord<K,V> record, Handler<AsyncResult<Void>> handler)
WriteStream#write(T) but with an handler called when the operation completeswrite in interface WriteStream<KafkaProducerRecord<K,V>>write in interface KafkaProducer<K,V>public KafkaProducer<K,V> send(KafkaProducerRecord<K,V> record)
KafkaProducersend in interface KafkaProducer<K,V>record - record to writepublic KafkaProducer<K,V> send(KafkaProducerRecord<K,V> record, Handler<AsyncResult<RecordMetadata>> handler)
KafkaProducersend in interface KafkaProducer<K,V>record - record to writehandler - handler called on operation completedpublic KafkaProducer<K,V> partitionsFor(String topic, Handler<AsyncResult<List<PartitionInfo>>> handler)
KafkaProducerpartitionsFor in interface KafkaProducer<K,V>topic - topic partition for which getting partitions infohandler - handler called on operation completedpublic void end()
WriteStreamOnce the stream has ended, it cannot be used any more.
end in interface WriteStream<KafkaProducerRecord<K,V>>public void end(Handler<AsyncResult<Void>> handler)
WriteStreamWriteStream.end() but with an handler called when the operation completesend in interface WriteStream<KafkaProducerRecord<K,V>>public void end(KafkaProducerRecord<K,V> kafkaProducerRecord)
WriteStreamWriteStream.end() but writes some data to the stream before ending.end in interface WriteStream<KafkaProducerRecord<K,V>>kafkaProducerRecord - the data to writepublic KafkaProducer<K,V> setWriteQueueMaxSize(int size)
WriteStreammaxSize. 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
Pump to provide flow control.
The value is defined by the implementation of the stream, e.g in bytes for a
NetSocket, the number of Message for a
MessageProducer, etc...setWriteQueueMaxSize in interface WriteStream<KafkaProducerRecord<K,V>>setWriteQueueMaxSize in interface KafkaProducer<K,V>size - the max size of the write streampublic boolean writeQueueFull()
WriteStreamtrue if there are more bytes in the write queue than the value set using WriteStream.setWriteQueueMaxSize(int)writeQueueFull in interface WriteStream<KafkaProducerRecord<K,V>>writeQueueFull in interface KafkaProducer<K,V>public KafkaProducer<K,V> drainHandler(Handler<Void> handler)
WriteStreamPump 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.drainHandler in interface WriteStream<KafkaProducerRecord<K,V>>drainHandler in interface KafkaProducer<K,V>handler - the handlerpublic KafkaProducer<K,V> flush(Handler<Void> completionHandler)
KafkaProducerflush in interface KafkaProducer<K,V>completionHandler - handler called on operation completedpublic void close()
KafkaProducerclose in interface KafkaProducer<K,V>public void close(Handler<AsyncResult<Void>> completionHandler)
KafkaProducerclose in interface KafkaProducer<K,V>completionHandler - handler called on operation completedpublic void close(long timeout,
Handler<AsyncResult<Void>> completionHandler)
KafkaProducerclose in interface KafkaProducer<K,V>timeout - timeout to wait for closingcompletionHandler - handler called on operation completedpublic KafkaWriteStream<K,V> asStream()
asStream in interface KafkaProducer<K,V>KafkaWriteStream instanceCopyright © 2020. All rights reserved.