Package io.vertx.kafka.client.producer
Interface KafkaProducer<K,V>
- All Superinterfaces:
StreamBase,WriteStream<KafkaProducerRecord<K,V>>
Vert.x Kafka producer.
The WriteStream.write(Object) provides global control over writing a record.
-
Method Summary
Modifier and TypeMethodDescriptionLikeabortTransaction(Handler)but with a future of the resultabortTransaction(Handler<AsyncResult<Void>> handler) Aborts the ongoing transaction.asStream()LikebeginTransaction(Handler)but with a future of the resultbeginTransaction(Handler<AsyncResult<Void>> handler) Starts a new kafka transaction.close()Close the producerclose(long timeout) Likeclose(long, Handler)but returns aFutureof the asynchronous resultvoidclose(long timeout, Handler<AsyncResult<Void>> completionHandler) Close the producervoidclose(Handler<AsyncResult<Void>> completionHandler) Close the producerLikecommitTransaction(Handler)but with a future of the resultcommitTransaction(Handler<AsyncResult<Void>> handler) Commits the ongoing transaction.static <K,V> KafkaProducer<K, V> Create a new KafkaProducer instancestatic <K,V> KafkaProducer<K, V> Create a new KafkaProducer instancestatic <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 instancestatic <K,V> KafkaProducer<K, V> create(Vertx vertx, Properties config) Create a new KafkaProducer instancestatic <K,V> KafkaProducer<K, V> create(Vertx vertx, Properties config, Class<K> keyType, Class<V> valueType) Create a new KafkaProducer instancestatic <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 instancestatic <K,V> KafkaProducer<K, V> Create a new KafkaProducer instance from a nativeProducer.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 nativeProducer.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 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, 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 samenamestatic <K,V> KafkaProducer<K, V> 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 samenamestatic <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 samenamestatic <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 samenamestatic <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 samenamestatic <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 samenamedrainHandler(Handler<Void> handler) exceptionHandler(Handler<Throwable> handler) flush()Likeflush(Handler)but returns aFutureof the asynchronous resultflush(Handler<AsyncResult<Void>> completionHandler) Invoking this method makes all buffered records immediately available to writeLikeinitTransactions(Handler)but with a future of the resultinitTransactions(Handler<AsyncResult<Void>> handler) Initializes the underlying kafka transactional producer.partitionsFor(String topic) LikepartitionsFor(String, Handler)but returns aFutureof the asynchronous resultpartitionsFor(String topic, Handler<AsyncResult<List<PartitionInfo>>> handler) Get the partition metadata for the give topic.send(KafkaProducerRecord<K, V> record) Asynchronously write a record to a topicsend(KafkaProducerRecord<K, V> record, Handler<AsyncResult<RecordMetadata>> handler) Asynchronously write a record to a topicsetWriteQueueMaxSize(int i) unwrap()Methods inherited from interface io.vertx.core.streams.WriteStream
end, end, end, end, write, write, writeQueueFull
-
Method Details
-
create
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 nativeProducer.- Parameters:
vertx- Vert.x instance to useproducer- the Kafka producer to wrap- Returns:
- an instance of the KafkaProducer
-
create
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 nativeProducer.- Parameters:
vertx- Vert.x instance to useproducer- the Kafka producer to wrapoptions- options used only for tracing settings- Returns:
- an instance of the KafkaProducer
-
create
Create a new KafkaProducer instance- Parameters:
vertx- Vert.x instance to useconfig- Kafka producer configuration- Returns:
- an instance of the KafkaProducer
-
create
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- Parameters:
vertx- Vert.x instance to useconfig- Kafka producer configurationkeySerializer- key serializervalueSerializer- value serializer- Returns:
- an instance of the KafkaProducer
-
create
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
-
create
Create a new KafkaProducer instance- Parameters:
vertx- Vert.x instance to useconfig- Kafka producer configuration- Returns:
- an instance of the KafkaProducer
-
create
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- Parameters:
vertx- Vert.x instance to useconfig- Kafka producer configurationkeySerializer- key serializervalueSerializer- value serializer- Returns:
- an instance of the KafkaProducer
-
create
static <K,V> KafkaProducer<K,V> create(Vertx vertx, Properties 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
Initializes the underlying kafka transactional producer. SeeinitTransactions()()}- Parameters:
handler- handler called on operation completed- Returns:
- current KafkaWriteStream instance
-
initTransactions
LikeinitTransactions(Handler)but with a future of the result -
beginTransaction
Starts a new kafka transaction. SeebeginTransaction()- Parameters:
handler- handler called on operation completed- Returns:
- current KafkaWriteStream instance
-
beginTransaction
LikebeginTransaction(Handler)but with a future of the result -
commitTransaction
Commits the ongoing transaction. SeecommitTransaction()- Parameters:
handler- handler called on operation completed- Returns:
- current KafkaWriteStream instance
-
commitTransaction
LikecommitTransaction(Handler)but with a future of the result -
abortTransaction
Aborts the ongoing transaction. SeeKafkaProducer.abortTransaction()- Parameters:
handler- handler called on operation completed- Returns:
- current KafkaWriteStream instance
-
abortTransaction
LikeabortTransaction(Handler)but with a future of the result -
exceptionHandler
- Specified by:
exceptionHandlerin interfaceStreamBase- Specified by:
exceptionHandlerin interfaceWriteStream<K>
-
setWriteQueueMaxSize
- Specified by:
setWriteQueueMaxSizein interfaceWriteStream<K>
-
drainHandler
- Specified by:
drainHandlerin interfaceWriteStream<K>
-
send
Asynchronously write a record to a topic- Parameters:
record- record to write- Returns:
- a
Futurecompleted with the record metadata
-
send
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
-
partitionsFor
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
LikepartitionsFor(String, Handler)but returns aFutureof the asynchronous result -
flush
Invoking this method makes all buffered records immediately available to write- Parameters:
completionHandler- handler called on operation completed- Returns:
- current KafkaProducer instance
-
flush
Likeflush(Handler)but returns aFutureof the asynchronous result -
close
Close the producer- Returns:
- a
Futurecompleted with the operation result
-
close
Close the producer- Parameters:
completionHandler- handler called on operation completed
-
close
Likeclose(long, Handler)but returns aFutureof the asynchronous result -
close
Close the producer- Parameters:
timeout- timeout to wait for closingcompletionHandler- handler called on operation completed
-
asStream
KafkaWriteStream<K,V> asStream()- Returns:
- underlying
KafkaWriteStreaminstance
-
unwrap
- Returns:
- the underlying producer