Interface KafkaProducer<K,V>
-
- All Superinterfaces:
StreamBase,WriteStream<KafkaProducerRecord<K,V>>
public interface KafkaProducer<K,V> extends WriteStream<KafkaProducerRecord<K,V>>
Vert.x Kafka producer.The
WriteStream.write(Object)provides global control over writing a record.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description Future<Void>abortTransaction()Aborts the ongoing transaction.KafkaWriteStream<K,V>asStream()Future<Void>beginTransaction()Starts a new kafka transaction.Future<Void>close()Close the producerFuture<Void>close(long timeout)Close the producerFuture<Void>commitTransaction()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>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(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(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>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 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 samenameKafkaProducer<K,V>drainHandler(Handler<Void> handler)KafkaProducer<K,V>exceptionHandler(Handler<Throwable> handler)Future<Void>flush()Invoking this method makes all buffered records immediately available to writeFuture<Void>initTransactions()Initializes the underlying kafka transactional producer.Future<List<PartitionInfo>>partitionsFor(String topic)Get the partition metadata for the give topic.Future<RecordMetadata>send(KafkaProducerRecord<K,V> record)Asynchronously write a record to a topicKafkaProducer<K,V>setWriteQueueMaxSize(int i)org.apache.kafka.clients.producer.Producer<K,V>unwrap()-
Methods inherited from interface io.vertx.core.streams.WriteStream
end, end, write, writeQueueFull
-
-
-
-
Method Detail
-
createShared
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 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
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
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
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 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 configurationkeySerializer- key serializervalueSerializer- value serializer- Returns:
- an instance of the KafkaProducer
-
createShared
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
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 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 configurationkeySerializer- key serializervalueSerializer- value serializer- Returns:
- an instance of the KafkaProducer
-
createShared
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 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
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 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 optionskeySerializer- key serializervalueSerializer- value serializer- Returns:
- an instance of the KafkaProducer
-
createShared
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
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
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
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
static <K,V> KafkaProducer<K,V> create(Vertx vertx, Properties config)
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
Future<Void> initTransactions()
Initializes the underlying kafka transactional producer. SeeinitTransactions()()}- Returns:
- a future notified with the result
-
beginTransaction
Future<Void> beginTransaction()
Starts a new kafka transaction. SeebeginTransaction()- Returns:
- a future notified with the result
-
commitTransaction
Future<Void> commitTransaction()
Commits the ongoing transaction. SeecommitTransaction()- Returns:
- a future notified with the result
-
abortTransaction
Future<Void> abortTransaction()
Aborts the ongoing transaction. SeeKafkaProducer.abortTransaction()- Returns:
- a future notified with the result
-
exceptionHandler
KafkaProducer<K,V> exceptionHandler(Handler<Throwable> handler)
- Specified by:
exceptionHandlerin interfaceStreamBase- Specified by:
exceptionHandlerin interfaceWriteStream<K>
-
setWriteQueueMaxSize
KafkaProducer<K,V> setWriteQueueMaxSize(int i)
- Specified by:
setWriteQueueMaxSizein interfaceWriteStream<K>
-
drainHandler
KafkaProducer<K,V> drainHandler(Handler<Void> handler)
- Specified by:
drainHandlerin interfaceWriteStream<K>
-
send
Future<RecordMetadata> send(KafkaProducerRecord<K,V> record)
Asynchronously write a record to a topic- Parameters:
record- record to write- Returns:
- a
Futurecompleted with the record metadata
-
partitionsFor
Future<List<PartitionInfo>> partitionsFor(String topic)
Get the partition metadata for the give topic.- Parameters:
topic- topic partition for which getting partitions info- Returns:
- a future notified with the result
-
flush
Future<Void> flush()
Invoking this method makes all buffered records immediately available to write- Returns:
- a future notified with the result
-
close
Future<Void> close(long timeout)
Close the producer- Returns:
- a future notified with the result
-
asStream
KafkaWriteStream<K,V> asStream()
- Returns:
- underlying
KafkaWriteStreaminstance
-
-