public interface KafkaProducer<K,V> extends WriteStream<KafkaProducerRecord<K,V>>
The WriteStream.write(Object)
provides global control over writing a record.
Modifier and Type | Method and Description |
---|---|
Future<Void> |
abortTransaction()
Like
abortTransaction(Handler) but with a future of the result |
KafkaProducer<K,V> |
abortTransaction(Handler<AsyncResult<Void>> handler)
Aborts the ongoing transaction.
|
KafkaWriteStream<K,V> |
asStream() |
Future<Void> |
beginTransaction()
Like
beginTransaction(Handler) but with a future of the result |
KafkaProducer<K,V> |
beginTransaction(Handler<AsyncResult<Void>> handler)
Starts a new kafka transaction.
|
Future<Void> |
close()
Close the producer
|
void |
close(Handler<AsyncResult<Void>> completionHandler)
Close the producer
|
Future<Void> |
close(long timeout)
Like
close(long, Handler) but returns a Future of the asynchronous result |
void |
close(long timeout,
Handler<AsyncResult<Void>> completionHandler)
Close the producer
|
Future<Void> |
commitTransaction()
Like
commitTransaction(Handler) but with a future of the result |
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 instance
|
static <K,V> KafkaProducer<K,V> |
create(Vertx vertx,
Map<String,String> config,
Class<K> keyType,
Class<V> valueType)
Create a new KafkaProducer instance
|
static <K,V> KafkaProducer<K,V> |
create(Vertx vertx,
Map<String,String> config,
org.apache.kafka.common.serialization.Serializer<K> keySerializer,
org.apache.kafka.common.serialization.Serializer<V> valueSerializer)
Create a new KafkaProducer instance
|
static <K,V> KafkaProducer<K,V> |
create(Vertx vertx,
org.apache.kafka.clients.producer.Producer<K,V> producer)
Create a new KafkaProducer instance from a native
Producer . |
static <K,V> KafkaProducer<K,V> |
create(Vertx vertx,
org.apache.kafka.clients.producer.Producer<K,V> producer,
KafkaClientOptions options)
Create a new KafkaProducer instance from a native
Producer . |
static <K,V> KafkaProducer<K,V> |
create(Vertx vertx,
Properties config)
Create a new KafkaProducer instance
|
static <K,V> KafkaProducer<K,V> |
create(Vertx vertx,
Properties config,
Class<K> keyType,
Class<V> valueType)
Create a new KafkaProducer instance
|
static <K,V> KafkaProducer<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 KafkaProducer instance
|
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 same
name |
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 same
name |
static <K,V> KafkaProducer<K,V> |
createShared(Vertx vertx,
String name,
KafkaClientOptions options,
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,
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.
|
KafkaProducer<K,V> |
exceptionHandler(Handler<Throwable> handler)
Set an exception handler on the write stream.
|
Future<Void> |
flush()
Like
flush(Handler) but returns a Future of the asynchronous result |
KafkaProducer<K,V> |
flush(Handler<AsyncResult<Void>> completionHandler)
Invoking this method makes all buffered records immediately available to write
|
Future<Void> |
initTransactions()
Like
initTransactions(Handler) but with a future of the result |
KafkaProducer<K,V> |
initTransactions(Handler<AsyncResult<Void>> handler)
Initializes the underlying kafka transactional producer.
|
Future<List<PartitionInfo>> |
partitionsFor(String topic)
Like
partitionsFor(String, Handler) but returns a Future of the asynchronous result |
KafkaProducer<K,V> |
partitionsFor(String topic,
Handler<AsyncResult<List<PartitionInfo>>> handler)
Get the partition metadata for the give topic.
|
Future<RecordMetadata> |
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 i)
Set the maximum size of the write queue to
maxSize . |
org.apache.kafka.clients.producer.Producer<K,V> |
unwrap() |
end, end, end, end, write, write, writeQueueFull
static <K,V> KafkaProducer<K,V> createShared(Vertx vertx, String name, Properties config)
name
When close
has been called for each shared producer the resources will be released.
Calling end
closes all shared producers.
vertx
- Vert.x instance to usename
- the producer name to identify itconfig
- Kafka producer configurationstatic <K,V> KafkaProducer<K,V> createShared(Vertx vertx, String name, Map<String,String> config)
name
When close
has been called for each shared producer the resources will be released.
Calling end
closes all shared producers.
vertx
- Vert.x instance to usename
- the producer name to identify itconfig
- Kafka producer configurationstatic <K,V> KafkaProducer<K,V> createShared(Vertx vertx, String name, KafkaClientOptions options)
name
When close
has been called for each shared producer the resources will be released.
Calling end
closes all shared producers.
vertx
- Vert.x instance to usename
- the producer name to identify itoptions
- Kafka producer optionsstatic <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)
name
When close
has been called for each shared producer the resources will be released.
Calling end
closes all shared producers.
vertx
- Vert.x instance to usename
- the producer name to identify itconfig
- Kafka producer configurationkeySerializer
- key serializervalueSerializer
- value serializerstatic <K,V> KafkaProducer<K,V> createShared(Vertx vertx, String name, Map<String,String> config, Class<K> keyType, Class<V> valueType)
name
When close
has been called for each shared producer the resources will be released.
Calling end
closes all shared producers.
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 serializationstatic <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)
name
When close
has been called for each shared producer the resources will be released.
Calling end
closes all shared producers.
vertx
- Vert.x instance to usename
- the producer name to identify itconfig
- Kafka producer configurationkeySerializer
- key serializervalueSerializer
- value serializerstatic <K,V> KafkaProducer<K,V> createShared(Vertx vertx, String name, Properties config, Class<K> keyType, Class<V> valueType)
name
When close
has been called for each shared producer the resources will be released.
Calling end
closes all shared producers.
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 serializationstatic <K,V> KafkaProducer<K,V> createShared(Vertx vertx, String name, KafkaClientOptions options, org.apache.kafka.common.serialization.Serializer<K> keySerializer, org.apache.kafka.common.serialization.Serializer<V> valueSerializer)
name
When close
has been called for each shared producer the resources will be released.
Calling end
closes all shared producers.
vertx
- Vert.x instance to usename
- the producer name to identify itoptions
- Kafka producer optionskeySerializer
- key serializervalueSerializer
- value serializerstatic <K,V> KafkaProducer<K,V> createShared(Vertx vertx, String name, KafkaClientOptions options, Class<K> keyType, Class<V> valueType)
name
When close
has been called for each shared producer the resources will be released.
Calling end
closes all shared producers.
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 serializationstatic <K,V> KafkaProducer<K,V> create(Vertx vertx, org.apache.kafka.clients.producer.Producer<K,V> producer)
Producer
.vertx
- Vert.x instance to useproducer
- the Kafka producer to wrapstatic <K,V> KafkaProducer<K,V> create(Vertx vertx, org.apache.kafka.clients.producer.Producer<K,V> producer, KafkaClientOptions options)
Producer
.vertx
- Vert.x instance to useproducer
- the Kafka producer to wrapoptions
- options used only for tracing settingsstatic <K,V> KafkaProducer<K,V> create(Vertx vertx, Map<String,String> config)
vertx
- Vert.x instance to useconfig
- Kafka producer configurationstatic <K,V> KafkaProducer<K,V> create(Vertx vertx, Map<String,String> config, org.apache.kafka.common.serialization.Serializer<K> keySerializer, org.apache.kafka.common.serialization.Serializer<V> valueSerializer)
vertx
- Vert.x instance to useconfig
- Kafka producer configurationkeySerializer
- key serializervalueSerializer
- value serializerstatic <K,V> KafkaProducer<K,V> create(Vertx vertx, Map<String,String> config, Class<K> keyType, Class<V> valueType)
vertx
- Vert.x instance to useconfig
- Kafka producer configurationkeyType
- class type for the key serializationvalueType
- class type for the value serializationstatic <K,V> KafkaProducer<K,V> create(Vertx vertx, Properties config)
vertx
- Vert.x instance to useconfig
- Kafka producer configurationstatic <K,V> KafkaProducer<K,V> create(Vertx vertx, Properties config, org.apache.kafka.common.serialization.Serializer<K> keySerializer, org.apache.kafka.common.serialization.Serializer<V> valueSerializer)
vertx
- Vert.x instance to useconfig
- Kafka producer configurationkeySerializer
- key serializervalueSerializer
- value serializerstatic <K,V> KafkaProducer<K,V> create(Vertx vertx, Properties config, Class<K> keyType, Class<V> valueType)
vertx
- Vert.x instance to useconfig
- Kafka producer configurationkeyType
- class type for the key serializationvalueType
- class type for the value serializationKafkaProducer<K,V> initTransactions(Handler<AsyncResult<Void>> handler)
initTransactions()
()}handler
- handler called on operation completedFuture<Void> initTransactions()
initTransactions(Handler)
but with a future of the resultKafkaProducer<K,V> beginTransaction(Handler<AsyncResult<Void>> handler)
beginTransaction()
handler
- handler called on operation completedFuture<Void> beginTransaction()
beginTransaction(Handler)
but with a future of the resultKafkaProducer<K,V> commitTransaction(Handler<AsyncResult<Void>> handler)
commitTransaction()
handler
- handler called on operation completedFuture<Void> commitTransaction()
commitTransaction(Handler)
but with a future of the resultKafkaProducer<K,V> abortTransaction(Handler<AsyncResult<Void>> handler)
KafkaProducer.abortTransaction()
handler
- handler called on operation completedFuture<Void> abortTransaction()
abortTransaction(Handler)
but with a future of the resultKafkaProducer<K,V> exceptionHandler(Handler<Throwable> handler)
WriteStream
exceptionHandler
in interface StreamBase
exceptionHandler
in interface WriteStream<KafkaProducerRecord<K,V>>
handler
- the exception handlerKafkaProducer<K,V> setWriteQueueMaxSize(int i)
WriteStream
maxSize
. 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
Pipe
to provide flow control.
The value is defined by the implementation of the stream, e.g in bytes for a
NetSocket
, etc...setWriteQueueMaxSize
in interface WriteStream<KafkaProducerRecord<K,V>>
i
- the max size of the write streamKafkaProducer<K,V> drainHandler(Handler<Void> handler)
WriteStream
Pipe
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>>
handler
- the handlerFuture<RecordMetadata> send(KafkaProducerRecord<K,V> record)
record
- record to writeFuture
completed with the record metadataKafkaProducer<K,V> send(KafkaProducerRecord<K,V> record, Handler<AsyncResult<RecordMetadata>> handler)
record
- record to writehandler
- handler called on operation completedKafkaProducer<K,V> partitionsFor(String topic, Handler<AsyncResult<List<PartitionInfo>>> handler)
topic
- topic partition for which getting partitions infohandler
- handler called on operation completedFuture<List<PartitionInfo>> partitionsFor(String topic)
partitionsFor(String, Handler)
but returns a Future
of the asynchronous resultKafkaProducer<K,V> flush(Handler<AsyncResult<Void>> completionHandler)
completionHandler
- handler called on operation completedFuture<Void> flush()
flush(Handler)
but returns a Future
of the asynchronous resultvoid close(Handler<AsyncResult<Void>> completionHandler)
completionHandler
- handler called on operation completedFuture<Void> close(long timeout)
close(long, Handler)
but returns a Future
of the asynchronous resultvoid close(long timeout, Handler<AsyncResult<Void>> completionHandler)
timeout
- timeout to wait for closingcompletionHandler
- handler called on operation completedKafkaWriteStream<K,V> asStream()
KafkaWriteStream
instanceCopyright © 2024 Eclipse. All rights reserved.