Package org.springframework.kafka.core
Class DefaultTransactionIdSuffixStrategy
java.lang.Object
org.springframework.kafka.core.DefaultTransactionIdSuffixStrategy
- All Implemented Interfaces:
TransactionIdSuffixStrategy
public class DefaultTransactionIdSuffixStrategy
extends Object
implements TransactionIdSuffixStrategy
The
TransactionIdSuffixStrategy
implementation for managing transactional producer suffixes.
If the maxCache
is greater than 0, the suffixes will be cached and reused.
Otherwise, the suffixes will be generated on the fly.
The cache is per `transactional.id` prefix. The cache size is limited by the maxCache
.
A value of 0 means no caching and restriction, so the `transactional.id` will be generated on the fly.
- Since:
- 3.2
- Author:
- Ilya Starchenko
-
Constructor Summary
ConstructorDescriptionDefaultTransactionIdSuffixStrategy
(int maxCache) Construct a transaction id suffix strategy with the provided size of the cache. -
Method Summary
Modifier and TypeMethodDescriptionacquireSuffix
(String txIdPrefix) Acquire the suffix for the transactional producer from the cache or generate a new one if caching is disabled.void
releaseSuffix
(String txIdPrefix, String suffix) Release the suffix for the transactional producer.
-
Constructor Details
-
DefaultTransactionIdSuffixStrategy
public DefaultTransactionIdSuffixStrategy(int maxCache) Construct a transaction id suffix strategy with the provided size of the cache.- Parameters:
maxCache
- the maximum size of the cache.
-
-
Method Details
-
acquireSuffix
Acquire the suffix for the transactional producer from the cache or generate a new one if caching is disabled.- Specified by:
acquireSuffix
in interfaceTransactionIdSuffixStrategy
- Parameters:
txIdPrefix
- the transaction id prefix.- Returns:
- the suffix.
- Throws:
NoProducerAvailableException
- if caching is enabled and no suffixes are available.
-
releaseSuffix
Description copied from interface:TransactionIdSuffixStrategy
Release the suffix for the transactional producer.- Specified by:
releaseSuffix
in interfaceTransactionIdSuffixStrategy
- Parameters:
txIdPrefix
- the transaction id prefix.suffix
- the suffix.
-