Package org.springframework.kafka.core
Class ProducerFactoryUtils
java.lang.Object
org.springframework.kafka.core.ProducerFactoryUtils
Helper class for managing a Spring based Kafka
DefaultKafkaProducerFactory
in particular for obtaining transactional Kafka resources for a given ProducerFactory.
Mainly for internal use within the framework.
- Author:
- Gary Russell
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <K,
V> KafkaResourceHolder<K, V> getTransactionalResourceHolder
(ProducerFactory<K, V> producerFactory) Obtain a Producer that is synchronized with the current transaction, if any.static <K,
V> KafkaResourceHolder<K, V> getTransactionalResourceHolder
(ProducerFactory<K, V> producerFactory, String txIdPrefix, Duration closeTimeout) Obtain a Producer that is synchronized with the current transaction, if any.static <K,
V> KafkaResourceHolder<K, V> getTransactionalResourceHolder
(ProducerFactory<K, V> producerFactory, Duration closeTimeout) Obtain a Producer that is synchronized with the current transaction, if any.static <K,
V> void releaseResources
(KafkaResourceHolder<K, V> resourceHolder)
-
Field Details
-
DEFAULT_CLOSE_TIMEOUT
The default close timeout (5 seconds).
-
-
Method Details
-
getTransactionalResourceHolder
public static <K,V> KafkaResourceHolder<K,V> getTransactionalResourceHolder(ProducerFactory<K, V> producerFactory) Obtain a Producer that is synchronized with the current transaction, if any.- Type Parameters:
K
- the key type.V
- the value type.- Parameters:
producerFactory
- the ProducerFactory to obtain a Channel for- Returns:
- the resource holder.
-
getTransactionalResourceHolder
public static <K,V> KafkaResourceHolder<K,V> getTransactionalResourceHolder(ProducerFactory<K, V> producerFactory, Duration closeTimeout) Obtain a Producer that is synchronized with the current transaction, if any.- Type Parameters:
K
- the key type.V
- the value type.- Parameters:
producerFactory
- the ProducerFactory to obtain a Channel forcloseTimeout
- the producer close timeout.- Returns:
- the resource holder.
- Since:
- 2.1.14
-
getTransactionalResourceHolder
public static <K,V> KafkaResourceHolder<K,V> getTransactionalResourceHolder(ProducerFactory<K, V> producerFactory, @Nullable String txIdPrefix, Duration closeTimeout) Obtain a Producer that is synchronized with the current transaction, if any.- Type Parameters:
K
- the key type.V
- the value type.- Parameters:
producerFactory
- the ProducerFactory to obtain a Channel fortxIdPrefix
- the transaction id prefix; if null, the producer factory prefix is used.closeTimeout
- the producer close timeout.- Returns:
- the resource holder.
- Since:
- 2.3
-
releaseResources
-