Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@
* @return the merged properties.
*/
public Map<String, Object> mergedConsumerConfiguration() {
Map<String, Object> consumerConfiguration = new HashMap<>(this.kafkaProperties.buildConsumerProperties());

Check warning on line 403 in binders/kafka-binder/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/properties/KafkaBinderConfigurationProperties.java

View workflow job for this annotation

GitHub Actions / Build and Verify

buildConsumerProperties() in org.springframework.boot.kafka.autoconfigure.KafkaProperties has been deprecated and marked for removal
if (!consumerConfiguration.containsKey(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG) && this.kafkaConnectionDetails != null) {
consumerConfiguration.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, this.kafkaConnectionDetails.getConsumer().getBootstrapServers());
}
Expand Down Expand Up @@ -429,7 +429,7 @@
* @return the merged properties.
*/
public Map<String, Object> mergedProducerConfiguration() {
Map<String, Object> producerConfiguration = new HashMap<>(this.kafkaProperties.buildProducerProperties());

Check warning on line 432 in binders/kafka-binder/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/properties/KafkaBinderConfigurationProperties.java

View workflow job for this annotation

GitHub Actions / Build and Verify

buildProducerProperties() in org.springframework.boot.kafka.autoconfigure.KafkaProperties has been deprecated and marked for removal
if (!producerConfiguration.containsKey(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG) && this.kafkaConnectionDetails != null) {
producerConfiguration.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, this.kafkaConnectionDetails.getProducer().getBootstrapServers());
}
Expand Down Expand Up @@ -543,6 +543,8 @@

private String transactionIdPrefix;

private Duration maxAge;

public String getTransactionIdPrefix() {
return this.transactionIdPrefix;
}
Expand All @@ -551,6 +553,14 @@
this.transactionIdPrefix = transactionIdPrefix;
}

public Duration getMaxAge() {
return this.maxAge;
}

public void setMaxAge(Duration maxAge) {
this.maxAge = maxAge;
}

public CombinedProducerProperties getProducer() {
return this.producer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.Collections;
import java.util.Map;

Expand Down Expand Up @@ -47,6 +48,17 @@ void defaultRequiredAcksIsAll() {
assertThat(kafkaBinderConfigurationProperties.getRequiredAcks()).isEqualTo("all");
}

@Test
void transactionMaxAgeCanBeConfigured() {
KafkaBinderConfigurationProperties.Transaction transaction =
new KafkaBinderConfigurationProperties.Transaction();

Duration maxAge = Duration.ofMinutes(5);
transaction.setMaxAge(maxAge);

assertThat(transaction.getMaxAge()).isEqualTo(maxAge);
}

@Test
@SuppressWarnings("unchecked")
void mergedConsumerConfigurationFiltersGroupIdFromKafkaProperties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,10 @@ protected DefaultKafkaProducerFactory<byte[], byte[]> getProducerFactory(
props);
if (transactionIdPrefix != null) {
producerFactory.setTransactionIdPrefix(transactionIdPrefix);
Duration maxAge = this.configurationProperties.getTransaction().getMaxAge();
if (maxAge != null) {
producerFactory.setMaxAge(maxAge);
}
}
if (kafkaProducerProperties.getCloseTimeout() > 0) {
producerFactory.setPhysicalCloseTimeout(kafkaProducerProperties.getCloseTimeout());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.springframework.cloud.stream.binder.kafka;

import java.lang.reflect.Field;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -47,6 +48,7 @@ public class KafkaBinderConfigurationWithTransactionsTest {
.withUserConfiguration(IntegrationAutoConfiguration.class, KafkaBinderConfiguration.class, KafkaAutoConfiguration.class)
.withPropertyValues(
"spring.cloud.stream.kafka.binder.transaction.transaction-id-prefix=test-tx-",
"spring.cloud.stream.kafka.binder.transaction.max-age=5m",
"spring.kafka.bootstrap-servers=localhost:9092");

@Test
Expand Down Expand Up @@ -75,6 +77,14 @@ public void clientFactoryCustomizersAppliedToTransactionManager() {
ProducerFactory<?, ?> producerFactory = transactionManager.getProducerFactory();
assertThat(producerFactory).isNotNull();

org.springframework.kafka.core.DefaultKafkaProducerFactory<?, ?> defaultProducerFactory =
(org.springframework.kafka.core.DefaultKafkaProducerFactory<?, ?>) producerFactory;

assertThat(defaultProducerFactory.getClass())
.isEqualTo(org.springframework.kafka.core.DefaultKafkaProducerFactory.class);
assertThat(org.springframework.test.util.ReflectionTestUtils.getField(defaultProducerFactory, "maxAge"))
.isEqualTo(Duration.ofMinutes(5).toMillis());

// Verify customizer was applied - check if our flag was set
TransactionClientFactoryCustomizerConfig config =
context.getBean(TransactionClientFactoryCustomizerConfig.class);
Expand Down
Loading