K - the key type.V - the value type.public class DefaultKafkaProducerFactory<K,V> extends java.lang.Object implements ProducerFactory<K,V>, org.springframework.context.Lifecycle, org.springframework.beans.factory.DisposableBean
ProducerFactory implementation for the singleton shared Producer
instance.
This implementation will produce a new Producer instance (if transactions are not enabled).
for provided Map configs and optional Serializer keySerializer,
valueSerializer implementations on each createProducer()
invocation.
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 Lifecycle.stop() or DisposableBean.destroy().
Setting setTransactionIdPrefix(String) enables transactions; in which case, a cache
of producers is maintained; closing the producer returns it to the cache.
| Constructor and Description |
|---|
DefaultKafkaProducerFactory(java.util.Map<java.lang.String,java.lang.Object> configs) |
DefaultKafkaProducerFactory(java.util.Map<java.lang.String,java.lang.Object> configs,
org.apache.kafka.common.serialization.Serializer<K> keySerializer,
org.apache.kafka.common.serialization.Serializer<V> valueSerializer) |
| Modifier and Type | Method and Description |
|---|---|
protected org.apache.kafka.clients.producer.Producer<K,V> |
createKafkaProducer() |
org.apache.kafka.clients.producer.Producer<K,V> |
createProducer() |
protected org.apache.kafka.clients.producer.Producer<K,V> |
createTransactionalProducer() |
void |
destroy() |
java.util.Map<java.lang.String,java.lang.Object> |
getConfigurationProperties()
Return an unmodifiable reference to the configuration map for this factory.
|
boolean |
isRunning() |
void |
setKeySerializer(org.apache.kafka.common.serialization.Serializer<K> keySerializer) |
void |
setPhysicalCloseTimeout(int physicalCloseTimeout)
|
void |
setTransactionIdPrefix(java.lang.String transactionIdPrefix)
Set the transactional.id prefix.
|
void |
setValueSerializer(org.apache.kafka.common.serialization.Serializer<V> valueSerializer) |
void |
start() |
void |
stop() |
boolean |
transactionCapable() |
public DefaultKafkaProducerFactory(java.util.Map<java.lang.String,java.lang.Object> configs)
public void setKeySerializer(org.apache.kafka.common.serialization.Serializer<K> keySerializer)
public void setValueSerializer(org.apache.kafka.common.serialization.Serializer<V> valueSerializer)
public void setPhysicalCloseTimeout(int physicalCloseTimeout)
stop() or destroy() is invoked).
Specified in seconds; default .physicalCloseTimeout - the timeout in seconds.public void setTransactionIdPrefix(java.lang.String transactionIdPrefix)
transactionIdPrefix - the prefix.public java.util.Map<java.lang.String,java.lang.Object> getConfigurationProperties()
public boolean transactionCapable()
transactionCapable in interface ProducerFactory<K,V>public void destroy()
throws java.lang.Exception
destroy in interface org.springframework.beans.factory.DisposableBeanjava.lang.Exceptionpublic void start()
start in interface org.springframework.context.Lifecyclepublic void stop()
stop in interface org.springframework.context.Lifecyclepublic boolean isRunning()
isRunning in interface org.springframework.context.Lifecyclepublic org.apache.kafka.clients.producer.Producer<K,V> createProducer()
createProducer in interface ProducerFactory<K,V>