public class DefaultProducerFactory<K,V> extends Object implements ProducerFactory<K,V>
ProducerFactory implementation to produce a singleton shared Producer
instance.
The Producer instance is freed from the external Producer.close() invocation
with the internal wrapper. The real Producer.close() is called on the target
Producer during the shutDown().
Setting DefaultProducerFactory.Builder.withConfirmationMode(ConfirmationMode) to transactional produces a transactional producer; in
which case,
a cache of producers is maintained; closing the producer returns it to the cache.
If cache is full the producer will be closed KafkaProducer.close(long, TimeUnit) and evicted from cache.
| Modifier and Type | Class and Description |
|---|---|
static class |
DefaultProducerFactory.Builder<K,V> |
| Modifier and Type | Method and Description |
|---|---|
static <K,V> DefaultProducerFactory.Builder<K,V> |
builder(Map<String,Object> configs) |
ConfirmationMode |
confirmationMode()
Confirmation mode for all producer instances.
|
org.apache.kafka.clients.producer.Producer<K,V> |
createProducer()
Create a producer with the settings supplied in configuration properties.
|
void |
shutDown()
Closes all producer instances.
|
public org.apache.kafka.clients.producer.Producer<K,V> createProducer()
createProducer in interface ProducerFactory<K,V>public ConfirmationMode confirmationMode()
confirmationMode in interface ProducerFactory<K,V>public void shutDown()
shutDown in interface ProducerFactory<K,V>public static <K,V> DefaultProducerFactory.Builder<K,V> builder(Map<String,Object> configs)
K - key type.V - value type.configs - Kafka properties for creating a producer(s).Copyright © 2010–2018. All rights reserved.