diff --git a/spring-kafka/src/main/java/org/springframework/kafka/core/DefaultKafkaProducerFactory.java b/spring-kafka/src/main/java/org/springframework/kafka/core/DefaultKafkaProducerFactory.java index 0f9ce7b3..437d9cf6 100644 --- a/spring-kafka/src/main/java/org/springframework/kafka/core/DefaultKafkaProducerFactory.java +++ b/spring-kafka/src/main/java/org/springframework/kafka/core/DefaultKafkaProducerFactory.java @@ -470,13 +470,12 @@ public class DefaultKafkaProducerFactory extends KafkaResourceFactory * @return the producerProperties or a copy with the transaction ID set */ private Map ensureExistingTransactionIdPrefixInProperties(Map producerProperties) { - String transactionIdPrefix = getTransactionIdPrefix(); - if (StringUtils.hasText(transactionIdPrefix)) { - if (!producerProperties.containsKey(ProducerConfig.TRANSACTIONAL_ID_CONFIG)) { - Map producerPropertiesWithTxnId = new HashMap<>(producerProperties); - producerPropertiesWithTxnId.put(ProducerConfig.TRANSACTIONAL_ID_CONFIG, transactionIdPrefix); - return producerPropertiesWithTxnId; - } + String txIdPrefix = getTransactionIdPrefix(); + if (StringUtils.hasText(txIdPrefix) + && !producerProperties.containsKey(ProducerConfig.TRANSACTIONAL_ID_CONFIG)) { + Map producerPropertiesWithTxnId = new HashMap<>(producerProperties); + producerPropertiesWithTxnId.put(ProducerConfig.TRANSACTIONAL_ID_CONFIG, txIdPrefix); + return producerPropertiesWithTxnId; } return producerProperties;