Package io.vertx.kafka.client.producer
Interface KafkaProducer<K,V>
- All Superinterfaces:
io.vertx.core.streams.StreamBase,io.vertx.core.streams.WriteStream<KafkaProducerRecord<K,V>>
public interface KafkaProducer<K,V>
extends io.vertx.core.streams.WriteStream<KafkaProducerRecord<K,V>>
Vert.x Kafka producer.
The WriteStream.write(Object) provides global control over writing a record.
-
Method Summary
Modifier and TypeMethodDescriptionio.vertx.core.Future<Void> LikeabortTransaction(Handler)but with a future of the resultabortTransaction(io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler) Aborts the ongoing transaction.asStream()io.vertx.core.Future<Void> LikebeginTransaction(Handler)but with a future of the resultbeginTransaction(io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler) Starts a new kafka transaction.io.vertx.core.Future<Void> close()Close the producerio.vertx.core.Future<Void> close(long timeout) Likeclose(long, Handler)but returns aFutureof the asynchronous resultvoidClose the producervoidClose the producerio.vertx.core.Future<Void> LikecommitTransaction(Handler)but with a future of the resultcommitTransaction(io.vertx.core.Handler<io.vertx.core.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(io.vertx.core.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(io.vertx.core.Vertx vertx, Properties config) Create a new KafkaProducer instancestatic <K,V> KafkaProducer <K, V> create(io.vertx.core.Vertx vertx, Properties config, Class<K> keyType, Class<V> valueType) Create a new KafkaProducer instancestatic <K,V> KafkaProducer <K, V> create(io.vertx.core.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(io.vertx.core.Vertx vertx, org.apache.kafka.clients.producer.Producer<K, V> producer) Create a new KafkaProducer instance from a nativeProducer.static <K,V> KafkaProducer <K, V> create(io.vertx.core.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(io.vertx.core.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(io.vertx.core.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(io.vertx.core.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> createShared(io.vertx.core.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(io.vertx.core.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(io.vertx.core.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(io.vertx.core.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(io.vertx.core.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(io.vertx.core.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(io.vertx.core.Handler<Void> handler) exceptionHandler(io.vertx.core.Handler<Throwable> handler) io.vertx.core.Future<Void> flush()Likeflush(Handler)but returns aFutureof the asynchronous resultInvoking this method makes all buffered records immediately available to writeio.vertx.core.Future<Void> LikeinitTransactions(Handler)but with a future of the resultinitTransactions(io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler) Initializes the underlying kafka transactional producer.io.vertx.core.Future<List<PartitionInfo>> partitionsFor(String topic) LikepartitionsFor(String, Handler)but returns aFutureof the asynchronous resultpartitionsFor(String topic, io.vertx.core.Handler<io.vertx.core.AsyncResult<List<PartitionInfo>>> handler) Get the partition metadata for the give topic.io.vertx.core.Future<RecordMetadata> send(KafkaProducerRecord<K, V> record) Asynchronously write a record to a topicsend(KafkaProducerRecord<K, V> record, io.vertx.core.Handler<io.vertx.core.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(io.vertx.core.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(io.vertx.core.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(io.vertx.core.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(io.vertx.core.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(io.vertx.core.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(io.vertx.core.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
io.vertx.core.Future<Void> 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
io.vertx.core.Future<Void> beginTransaction()LikebeginTransaction(Handler)but with a future of the result -
commitTransaction
KafkaProducer<K,V> commitTransaction(io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler) Commits the ongoing transaction. SeecommitTransaction()- Parameters:
handler- handler called on operation completed- Returns:
- current KafkaWriteStream instance
-
commitTransaction
io.vertx.core.Future<Void> 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
io.vertx.core.Future<Void> abortTransaction()LikeabortTransaction(Handler)but with a future of the result -
exceptionHandler
- Specified by:
exceptionHandlerin interfaceio.vertx.core.streams.StreamBase- Specified by:
exceptionHandlerin interfaceio.vertx.core.streams.WriteStream<K>
-
setWriteQueueMaxSize
- Specified by:
setWriteQueueMaxSizein interfaceio.vertx.core.streams.WriteStream<K>
-
drainHandler
- Specified by:
drainHandlerin interfaceio.vertx.core.streams.WriteStream<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, io.vertx.core.Handler<io.vertx.core.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
KafkaProducer<K,V> partitionsFor(String topic, io.vertx.core.Handler<io.vertx.core.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
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
io.vertx.core.Future<Void> flush()Likeflush(Handler)but returns aFutureof the asynchronous result -
close
io.vertx.core.Future<Void> 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