Class DefaultKafkaProducerFactory<K,V>
- java.lang.Object
-
- org.springframework.kafka.core.KafkaResourceFactory
-
- org.springframework.kafka.core.DefaultKafkaProducerFactory<K,V>
-
- Type Parameters:
K- the key type.V- the value type.
- All Implemented Interfaces:
java.util.EventListener,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.DisposableBean,org.springframework.context.ApplicationContextAware,org.springframework.context.ApplicationListener<org.springframework.context.event.ContextStoppedEvent>,ProducerFactory<K,V>
public class DefaultKafkaProducerFactory<K,V> extends KafkaResourceFactory implements ProducerFactory<K,V>, org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.BeanNameAware, org.springframework.context.ApplicationListener<org.springframework.context.event.ContextStoppedEvent>, org.springframework.beans.factory.DisposableBean
TheProducerFactoryimplementation for asingletonsharedProducerinstance.This implementation will return the same
Producerinstance (if transactions are not enabled) for the providedMapconfigsand optionalSerializerimplementations on eachcreateProducer()invocation.If you are using
Serializers that have no-arg constructors and require no setup, then simplest to specifySerializerclasses againstProducerConfig.KEY_SERIALIZER_CLASS_CONFIGandProducerConfig.VALUE_SERIALIZER_CLASS_CONFIGkeys in theconfigspassed to theDefaultKafkaProducerFactoryconstructor.If that is not possible, but you are sure that at least one of the following is true:
- only one
Producerwill use theSerializers - you are using
Serializers that may be shared betweenProducerinstances (and specifically that their close() method is a no-op) - you are certain that there is no risk of any single
Producerbeing closed while otherProducerinstances with the sameSerializers are in use
Serializerinstances for one or both of the key and value serializers.If none of the above is true then you may provide a
Supplierfunction for one or bothSerializers which will be used to obtainSerializer(s) each time aProduceris created by the factory.The
Produceris wrapped and the underlyingKafkaProducerinstance is not actually closed whenProducer.close()is invoked. TheKafkaProduceris physically closed whenDisposableBean.destroy()is invoked or when the application context publishes aContextStoppedEvent. You can also invokereset().Setting
setTransactionIdPrefix(String)enables transactions; in which case, a cache of producers is maintained; closing a producer returns it to the cache. The producers are closed and the cache is cleared when the factory is destroyed, the application context stopped, or thereset()method is called.- Author:
- Gary Russell, Murali Reddy, Nakul Mishra, Artem Bilan, Chris Gilbert, Thomas Strauß
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classDefaultKafkaProducerFactory.CloseSafeProducer<K,V>A wrapper class for the delegate.-
Nested classes/interfaces inherited from interface org.springframework.kafka.core.ProducerFactory
ProducerFactory.Listener<K,V>
-
-
Field Summary
-
Fields inherited from interface org.springframework.kafka.core.ProducerFactory
DEFAULT_PHYSICAL_CLOSE_TIMEOUT
-
-
Constructor Summary
Constructors Constructor Description DefaultKafkaProducerFactory(java.util.Map<java.lang.String,java.lang.Object> configs)Construct a factory with the provided configuration.DefaultKafkaProducerFactory(java.util.Map<java.lang.String,java.lang.Object> configs, java.util.function.Supplier<org.apache.kafka.common.serialization.Serializer<K>> keySerializerSupplier, java.util.function.Supplier<org.apache.kafka.common.serialization.Serializer<V>> valueSerializerSupplier)Construct a factory with the provided configuration andSerializerSuppliers.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)Construct a factory with the provided configuration andSerializers.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(int index, ProducerFactory.Listener<K,V> listener)Add a listener at a specific index.voidaddListener(ProducerFactory.Listener<K,V> listener)Add a listener.voidaddPostProcessor(ProducerPostProcessor<K,V> postProcessor)Add a post processor.voidcloseProducerFor(java.lang.String suffix)Remove the specified producer from the cache and close it.voidcloseThreadBoundProducer()When usingsetProducerPerThread(boolean)(true), call this method to close and release this thread's producer.ProducerFactory<K,V>copyWithConfigurationOverride(java.util.Map<java.lang.String,java.lang.Object> overrideProperties)Copy properties of the instance and the given properties to create a new producer factory.protected org.apache.kafka.clients.producer.Producer<K,V>createKafkaProducer()Subclasses must return a raw producer which will be wrapped in aDefaultKafkaProducerFactory.CloseSafeProducer.org.apache.kafka.clients.producer.Producer<K,V>createNonTransactionalProducer()Create a non-transactional producer.org.apache.kafka.clients.producer.Producer<K,V>createProducer()Create a producer which will be transactional if the factory is so configured.org.apache.kafka.clients.producer.Producer<K,V>createProducer(java.lang.String txIdPrefixArg)Create a producer with an overridden transaction id prefix.protected org.apache.kafka.clients.producer.Producer<K,V>createRawProducer(java.util.Map<java.lang.String,java.lang.Object> rawConfigs)protected org.apache.kafka.clients.producer.Producer<K,V>createTransactionalProducer()Subclasses must return a producer from thegetCache()or a new raw producer wrapped in aDefaultKafkaProducerFactory.CloseSafeProducer.protected org.apache.kafka.clients.producer.Producer<K,V>createTransactionalProducer(java.lang.String txIdPrefix)protected org.apache.kafka.clients.producer.Producer<K,V>createTransactionalProducerForPartition()protected org.apache.kafka.clients.producer.Producer<K,V>createTransactionalProducerForPartition(java.lang.String txIdPrefix)voiddestroy()protected java.util.concurrent.BlockingQueue<DefaultKafkaProducerFactory.CloseSafeProducer<K,V>>getCache()protected java.util.concurrent.BlockingQueue<DefaultKafkaProducerFactory.CloseSafeProducer<K,V>>getCache(java.lang.String txIdPrefix)java.util.Map<java.lang.String,java.lang.Object>getConfigurationProperties()Return an unmodifiable reference to the configuration map for this factory.org.apache.kafka.common.serialization.Serializer<K>getKeySerializer()Return the configured key serializer (if provided as an object instead of a class name in the properties).java.util.function.Supplier<org.apache.kafka.common.serialization.Serializer<K>>getKeySerializerSupplier()Return a supplier for a key serializer.java.util.List<ProducerFactory.Listener<K,V>>getListeners()Get the current list of listeners.java.time.DurationgetPhysicalCloseTimeout()Get the physical close timeout.java.util.List<ProducerPostProcessor<K,V>>getPostProcessors()Get the current list of post processors.protected java.util.Map<java.lang.String,java.lang.Object>getProducerConfigs()Return the configuration of a producer.java.lang.StringgetTransactionIdPrefix()Return the transaction id prefix.protected java.util.Map<java.lang.String,java.lang.Object>getTxProducerConfigs(java.lang.String transactionId)Return the configuration of a transactional producer.org.apache.kafka.common.serialization.Serializer<V>getValueSerializer()Return the configured value serializer (if provided as an object instead of a class name in the properties).java.util.function.Supplier<org.apache.kafka.common.serialization.Serializer<V>>getValueSerializerSupplier()Return a supplier for a value serializer.booleanisProducerPerConsumerPartition()Return the producerPerConsumerPartition.booleanisProducerPerThread()Return true when there is a producer per thread.voidonApplicationEvent(org.springframework.context.event.ContextStoppedEvent event)voidremoveConfig(java.lang.String configKey)Remove the specified key from the configuration map.booleanremoveListener(ProducerFactory.Listener<K,V> listener)Remove a listener.booleanremovePostProcessor(ProducerPostProcessor<K,V> postProcessor)Remove a post processor.protected booleanremoveProducer(DefaultKafkaProducerFactory.CloseSafeProducer<K,V> producerToRemove, java.time.Duration timeout)Remove the single shared producer and a thread-bound instance if present.voidreset()Close theProducer(s) and clear the cache of transactionalProducer(s).voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext)voidsetBeanName(java.lang.String name)voidsetKeySerializer(org.apache.kafka.common.serialization.Serializer<K> keySerializer)Set a key serializer.voidsetKeySerializerSupplier(java.util.function.Supplier<org.apache.kafka.common.serialization.Serializer<K>> keySerializerSupplier)Set a supplier to supply instances of the key serializer.voidsetMaxAge(java.time.Duration maxAge)Set the maximum age for a producer; useful when using transactions and the broker might expire atransactional.iddue to inactivity.voidsetPhysicalCloseTimeout(int physicalCloseTimeout)The time to wait when physically closing the producer via the factory rather than closing the producer itself (whenreset(),#closeProducerFor(String), orcloseThreadBoundProducer()are invoked).voidsetProducerPerConsumerPartition(boolean producerPerConsumerPartition)Set to false to revert to the previous behavior of a simple incrementing transactional.id suffix for each producer instead of maintaining a producer for each group/topic/partition.voidsetProducerPerThread(boolean producerPerThread)Set to true to create a producer per thread instead of singleton that is shared by all clients.voidsetTransactionIdPrefix(java.lang.String transactionIdPrefix)Set a prefix for theProducerConfig.TRANSACTIONAL_ID_CONFIGconfig.voidsetValueSerializer(org.apache.kafka.common.serialization.Serializer<V> valueSerializer)Set a value serializer.voidsetValueSerializerSupplier(java.util.function.Supplier<org.apache.kafka.common.serialization.Serializer<V>> valueSerializerSupplier)Set a supplier to supply instances of the value serializer.booleantransactionCapable()Return true if the factory supports transactions.voidupdateConfigs(java.util.Map<java.lang.String,java.lang.Object> updates)Update the producer configuration map; useful for situations such as credential rotation.-
Methods inherited from class org.springframework.kafka.core.KafkaResourceFactory
checkBootstrap, getBootstrapServers, setBootstrapServersSupplier
-
-
-
-
Constructor Detail
-
DefaultKafkaProducerFactory
public DefaultKafkaProducerFactory(java.util.Map<java.lang.String,java.lang.Object> configs)
Construct a factory with the provided configuration.- Parameters:
configs- the configuration.
-
DefaultKafkaProducerFactory
public DefaultKafkaProducerFactory(java.util.Map<java.lang.String,java.lang.Object> configs, @Nullable org.apache.kafka.common.serialization.Serializer<K> keySerializer, @Nullable org.apache.kafka.common.serialization.Serializer<V> valueSerializer)Construct a factory with the provided configuration andSerializers. Also configures atransactionIdPrefixas a value from theProducerConfig.TRANSACTIONAL_ID_CONFIGif provided. This config is going to be overridden with a suffix for targetProducerinstance. The serializers'configure()methods will be called with the configuration map.- Parameters:
configs- the configuration.keySerializer- the keySerializer.valueSerializer- the valueSerializer.
-
DefaultKafkaProducerFactory
public DefaultKafkaProducerFactory(java.util.Map<java.lang.String,java.lang.Object> configs, @Nullable java.util.function.Supplier<org.apache.kafka.common.serialization.Serializer<K>> keySerializerSupplier, @Nullable java.util.function.Supplier<org.apache.kafka.common.serialization.Serializer<V>> valueSerializerSupplier)Construct a factory with the provided configuration andSerializerSuppliers. Also configures atransactionIdPrefixas a value from theProducerConfig.TRANSACTIONAL_ID_CONFIGif provided. This config is going to be overridden with a suffix for targetProducerinstance. When the suppliers are invoked to get an instance, the serializers'configure()methods will be called with the configuration map.- Parameters:
configs- the configuration.keySerializerSupplier- the keySerializersupplier function.valueSerializerSupplier- the valueSerializersupplier function.- Since:
- 2.3
-
-
Method Detail
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException- Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
setBeanName
public void setBeanName(java.lang.String name)
- Specified by:
setBeanNamein interfaceorg.springframework.beans.factory.BeanNameAware
-
setKeySerializer
public void setKeySerializer(@Nullable org.apache.kafka.common.serialization.Serializer<K> keySerializer)Set a key serializer.- Parameters:
keySerializer- the key serializer.
-
setValueSerializer
public void setValueSerializer(@Nullable org.apache.kafka.common.serialization.Serializer<V> valueSerializer)Set a value serializer.- Parameters:
valueSerializer- the value serializer.
-
setKeySerializerSupplier
public void setKeySerializerSupplier(java.util.function.Supplier<org.apache.kafka.common.serialization.Serializer<K>> keySerializerSupplier)
Set a supplier to supply instances of the key serializer.- Parameters:
keySerializerSupplier- the supplier.- Since:
- 2.8
-
setValueSerializerSupplier
public void setValueSerializerSupplier(java.util.function.Supplier<org.apache.kafka.common.serialization.Serializer<V>> valueSerializerSupplier)
Set a supplier to supply instances of the value serializer.- Parameters:
valueSerializerSupplier- the supplier.- Since:
- 2.8
-
setPhysicalCloseTimeout
public void setPhysicalCloseTimeout(int physicalCloseTimeout)
The time to wait when physically closing the producer via the factory rather than closing the producer itself (whenreset(),#closeProducerFor(String), orcloseThreadBoundProducer()are invoked). Specified in seconds; defaultProducerFactory.DEFAULT_PHYSICAL_CLOSE_TIMEOUT.- Parameters:
physicalCloseTimeout- the timeout in seconds.- Since:
- 1.0.7
-
getPhysicalCloseTimeout
public java.time.Duration getPhysicalCloseTimeout()
Get the physical close timeout.- Specified by:
getPhysicalCloseTimeoutin interfaceProducerFactory<K,V>- Returns:
- the timeout.
- Since:
- 2.5
-
setTransactionIdPrefix
public final void setTransactionIdPrefix(java.lang.String transactionIdPrefix)
Set a prefix for theProducerConfig.TRANSACTIONAL_ID_CONFIGconfig. By default aProducerConfig.TRANSACTIONAL_ID_CONFIGvalue from configs is used as a prefix in the target producer configs.- Parameters:
transactionIdPrefix- the prefix.- Since:
- 1.3
-
getTransactionIdPrefix
@Nullable public java.lang.String getTransactionIdPrefix()
Description copied from interface:ProducerFactoryReturn the transaction id prefix.- Specified by:
getTransactionIdPrefixin interfaceProducerFactory<K,V>- Returns:
- the prefix or null if not configured.
-
setProducerPerThread
public void setProducerPerThread(boolean producerPerThread)
Set to true to create a producer per thread instead of singleton that is shared by all clients. Clients must callcloseThreadBoundProducer()to physically close the producer when it is no longer needed. These producers will not be closed bydestroy()orreset().- Parameters:
producerPerThread- true for a producer per thread.- Since:
- 2.3
- See Also:
closeThreadBoundProducer()
-
isProducerPerThread
public boolean isProducerPerThread()
Description copied from interface:ProducerFactoryReturn true when there is a producer per thread.- Specified by:
isProducerPerThreadin interfaceProducerFactory<K,V>- Returns:
- the producer per thread.
-
setProducerPerConsumerPartition
public void setProducerPerConsumerPartition(boolean producerPerConsumerPartition)
Set to false to revert to the previous behavior of a simple incrementing transactional.id suffix for each producer instead of maintaining a producer for each group/topic/partition.- Parameters:
producerPerConsumerPartition- false to revert.- Since:
- 1.3.7
-
isProducerPerConsumerPartition
public boolean isProducerPerConsumerPartition()
Return the producerPerConsumerPartition.- Specified by:
isProducerPerConsumerPartitionin interfaceProducerFactory<K,V>- Returns:
- the producerPerConsumerPartition.
- Since:
- 1.3.8
-
getKeySerializer
@Nullable public org.apache.kafka.common.serialization.Serializer<K> getKeySerializer()
Description copied from interface:ProducerFactoryReturn the configured key serializer (if provided as an object instead of a class name in the properties).- Specified by:
getKeySerializerin interfaceProducerFactory<K,V>- Returns:
- the serializer.
-
getValueSerializer
@Nullable public org.apache.kafka.common.serialization.Serializer<V> getValueSerializer()
Description copied from interface:ProducerFactoryReturn the configured value serializer (if provided as an object instead of a class name in the properties).- Specified by:
getValueSerializerin interfaceProducerFactory<K,V>- Returns:
- the serializer.
-
getKeySerializerSupplier
public java.util.function.Supplier<org.apache.kafka.common.serialization.Serializer<K>> getKeySerializerSupplier()
Description copied from interface:ProducerFactoryReturn a supplier for a key serializer. Useful for cloning to make a similar factory.- Specified by:
getKeySerializerSupplierin interfaceProducerFactory<K,V>- Returns:
- the supplier.
-
getValueSerializerSupplier
public java.util.function.Supplier<org.apache.kafka.common.serialization.Serializer<V>> getValueSerializerSupplier()
Description copied from interface:ProducerFactoryReturn a supplier for a value serializer. Useful for cloning to make a similar factory.- Specified by:
getValueSerializerSupplierin interfaceProducerFactory<K,V>- Returns:
- the supplier.
-
getConfigurationProperties
public java.util.Map<java.lang.String,java.lang.Object> getConfigurationProperties()
Return an unmodifiable reference to the configuration map for this factory. Useful for cloning to make a similar factory.- Specified by:
getConfigurationPropertiesin interfaceProducerFactory<K,V>- Returns:
- the configs.
- Since:
- 1.3
-
getListeners
public java.util.List<ProducerFactory.Listener<K,V>> getListeners()
Get the current list of listeners.- Specified by:
getListenersin interfaceProducerFactory<K,V>- Returns:
- the listeners.
- Since:
- 2.5
-
getPostProcessors
public java.util.List<ProducerPostProcessor<K,V>> getPostProcessors()
Description copied from interface:ProducerFactoryGet the current list of post processors.- Specified by:
getPostProcessorsin interfaceProducerFactory<K,V>- Returns:
- the post processors.
-
setMaxAge
public void setMaxAge(java.time.Duration maxAge)
Set the maximum age for a producer; useful when using transactions and the broker might expire atransactional.iddue to inactivity.- Parameters:
maxAge- the maxAge to set- Since:
- 2.5.8
-
copyWithConfigurationOverride
public ProducerFactory<K,V> copyWithConfigurationOverride(java.util.Map<java.lang.String,java.lang.Object> overrideProperties)
Copy properties of the instance and the given properties to create a new producer factory.If the
DefaultKafkaProducerFactorymakes a copy of itself, the transaction id prefix is recovered from the properties. If you want to change the ID config, add a newProducerConfig.TRANSACTIONAL_ID_CONFIGkey to the override config.- Specified by:
copyWithConfigurationOverridein interfaceProducerFactory<K,V>- Parameters:
overrideProperties- the properties to be applied to the new factory- Returns:
DefaultKafkaProducerFactorywith properties applied- See Also:
KafkaTemplate(ProducerFactory, java.util.Map)
-
addListener
public void addListener(ProducerFactory.Listener<K,V> listener)
Add a listener.- Specified by:
addListenerin interfaceProducerFactory<K,V>- Parameters:
listener- the listener.- Since:
- 2.5
-
addListener
public void addListener(int index, ProducerFactory.Listener<K,V> listener)Add a listener at a specific index.- Specified by:
addListenerin interfaceProducerFactory<K,V>- Parameters:
index- the index (list position).listener- the listener.- Since:
- 2.5
-
removeListener
public boolean removeListener(ProducerFactory.Listener<K,V> listener)
Remove a listener.- Specified by:
removeListenerin interfaceProducerFactory<K,V>- Parameters:
listener- the listener.- Returns:
- true if removed.
- Since:
- 2.5
-
addPostProcessor
public void addPostProcessor(ProducerPostProcessor<K,V> postProcessor)
Description copied from interface:ProducerFactoryAdd a post processor.- Specified by:
addPostProcessorin interfaceProducerFactory<K,V>- Parameters:
postProcessor- the post processor.
-
removePostProcessor
public boolean removePostProcessor(ProducerPostProcessor<K,V> postProcessor)
Description copied from interface:ProducerFactoryRemove a post processor.- Specified by:
removePostProcessorin interfaceProducerFactory<K,V>- Parameters:
postProcessor- the post processor.- Returns:
- true if removed.
-
updateConfigs
public void updateConfigs(java.util.Map<java.lang.String,java.lang.Object> updates)
Description copied from interface:ProducerFactoryUpdate the producer configuration map; useful for situations such as credential rotation.- Specified by:
updateConfigsin interfaceProducerFactory<K,V>- Parameters:
updates- the configuration properties to update.
-
removeConfig
public void removeConfig(java.lang.String configKey)
Description copied from interface:ProducerFactoryRemove the specified key from the configuration map.- Specified by:
removeConfigin interfaceProducerFactory<K,V>- Parameters:
configKey- the key to remove.
-
transactionCapable
public boolean transactionCapable()
Description copied from interface:ProducerFactoryReturn true if the factory supports transactions.- Specified by:
transactionCapablein interfaceProducerFactory<K,V>- Returns:
- true if transactional.
-
destroy
public void destroy()
- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean
-
onApplicationEvent
public void onApplicationEvent(org.springframework.context.event.ContextStoppedEvent event)
- Specified by:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener<K>
-
reset
public void reset()
Close theProducer(s) and clear the cache of transactionalProducer(s).- Specified by:
resetin interfaceProducerFactory<K,V>- Since:
- 2.2
-
createProducer
public org.apache.kafka.clients.producer.Producer<K,V> createProducer()
Description copied from interface:ProducerFactoryCreate a producer which will be transactional if the factory is so configured.- Specified by:
createProducerin interfaceProducerFactory<K,V>- Returns:
- the producer.
- See Also:
ProducerFactory.transactionCapable()
-
createProducer
public org.apache.kafka.clients.producer.Producer<K,V> createProducer(@Nullable java.lang.String txIdPrefixArg)
Description copied from interface:ProducerFactoryCreate a producer with an overridden transaction id prefix.- Specified by:
createProducerin interfaceProducerFactory<K,V>- Parameters:
txIdPrefixArg- the transaction id prefix.- Returns:
- the producer.
-
createNonTransactionalProducer
public org.apache.kafka.clients.producer.Producer<K,V> createNonTransactionalProducer()
Description copied from interface:ProducerFactoryCreate a non-transactional producer.- Specified by:
createNonTransactionalProducerin interfaceProducerFactory<K,V>- Returns:
- the producer.
- See Also:
ProducerFactory.transactionCapable()
-
createKafkaProducer
protected org.apache.kafka.clients.producer.Producer<K,V> createKafkaProducer()
Subclasses must return a raw producer which will be wrapped in aDefaultKafkaProducerFactory.CloseSafeProducer.- Returns:
- the producer.
-
createTransactionalProducerForPartition
protected org.apache.kafka.clients.producer.Producer<K,V> createTransactionalProducerForPartition()
-
createTransactionalProducerForPartition
protected org.apache.kafka.clients.producer.Producer<K,V> createTransactionalProducerForPartition(java.lang.String txIdPrefix)
-
removeProducer
protected final boolean removeProducer(DefaultKafkaProducerFactory.CloseSafeProducer<K,V> producerToRemove, java.time.Duration timeout)
Remove the single shared producer and a thread-bound instance if present.- Parameters:
producerToRemove- the producer.timeout- the close timeout.- Returns:
- always true.
- Since:
- 2.2.13
-
createTransactionalProducer
protected org.apache.kafka.clients.producer.Producer<K,V> createTransactionalProducer()
Subclasses must return a producer from thegetCache()or a new raw producer wrapped in aDefaultKafkaProducerFactory.CloseSafeProducer.- Returns:
- the producer - cannot be null.
- Since:
- 1.3
-
createTransactionalProducer
protected org.apache.kafka.clients.producer.Producer<K,V> createTransactionalProducer(java.lang.String txIdPrefix)
-
createRawProducer
protected org.apache.kafka.clients.producer.Producer<K,V> createRawProducer(java.util.Map<java.lang.String,java.lang.Object> rawConfigs)
-
getCache
@Nullable protected java.util.concurrent.BlockingQueue<DefaultKafkaProducerFactory.CloseSafeProducer<K,V>> getCache()
-
getCache
@Nullable protected java.util.concurrent.BlockingQueue<DefaultKafkaProducerFactory.CloseSafeProducer<K,V>> getCache(java.lang.String txIdPrefix)
-
closeProducerFor
public void closeProducerFor(java.lang.String suffix)
Description copied from interface:ProducerFactoryRemove the specified producer from the cache and close it.- Specified by:
closeProducerForin interfaceProducerFactory<K,V>- Parameters:
suffix- the producer's transaction id suffix.
-
closeThreadBoundProducer
public void closeThreadBoundProducer()
When usingsetProducerPerThread(boolean)(true), call this method to close and release this thread's producer. Thread bound producers are not closed bydestroy()orreset()methods.- Specified by:
closeThreadBoundProducerin interfaceProducerFactory<K,V>- Since:
- 2.3
- See Also:
setProducerPerThread(boolean)
-
getProducerConfigs
protected java.util.Map<java.lang.String,java.lang.Object> getProducerConfigs()
Return the configuration of a producer.- Returns:
- the configuration of a producer.
- Since:
- 2.8.3
- See Also:
createKafkaProducer()
-
getTxProducerConfigs
protected java.util.Map<java.lang.String,java.lang.Object> getTxProducerConfigs(java.lang.String transactionId)
Return the configuration of a transactional producer.- Parameters:
transactionId- the transactionId.- Returns:
- the configuration of a transactional producer.
- Since:
- 2.8.3
- See Also:
doCreateTxProducer(String, String, BiPredicate)
-
-