Add support for Kafka batch listener

This commit adds a `spring.kafka.listener.batch-listener` property so
that a batch listener is created automatically.

See gh-9448
pull/9487/merge
mzagar 8 years ago committed by Stephane Nicoll
parent 4282e94c2c
commit 257f44357e

@ -68,6 +68,7 @@ public class ConcurrentKafkaListenerContainerFactoryConfigurer {
if (container.getConcurrency() != null) {
listenerContainerFactory.setConcurrency(container.getConcurrency());
}
listenerContainerFactory.setBatchListener(container.getBatchListener());
}
}

@ -672,6 +672,11 @@ public class KafkaProperties {
*/
private Long ackTime;
/**
* If true listener container factory will be configured to create batch listener.
*/
private boolean batchListener;
public AckMode getAckMode() {
return this.ackMode;
}
@ -712,6 +717,13 @@ public class KafkaProperties {
this.ackTime = ackTime;
}
public boolean getBatchListener() {
return this.batchListener;
}
public void setBatchListener(boolean batchListener) {
this.batchListener = batchListener;
}
}
public static class Ssl {

@ -176,6 +176,7 @@ public class KafkaAutoConfigurationTests {
"spring.kafka.listener.ack-time=456",
"spring.kafka.listener.concurrency=3",
"spring.kafka.listener.poll-timeout=2000",
"spring.kafka.listener.batch-listener=true",
"spring.kafka.jaas.enabled=true", "spring.kafka.jaas.login-module=foo",
"spring.kafka.jaas.control-flag=REQUISITE",
"spring.kafka.jaas.options.useKeyTab=true");
@ -198,6 +199,8 @@ public class KafkaAutoConfigurationTests {
assertThat(dfa.getPropertyValue("concurrency")).isEqualTo(3);
assertThat(dfa.getPropertyValue("containerProperties.pollTimeout"))
.isEqualTo(2000L);
assertThat(dfa.getPropertyValue("batchListener"))
.isEqualTo(true);
assertThat(this.context.getBeansOfType(KafkaJaasLoginModuleInitializer.class))
.hasSize(1);
KafkaJaasLoginModuleInitializer jaas = this.context

@ -986,6 +986,7 @@ content into your application; rather pick only the properties that you need.
spring.kafka.listener.ack-time= # Time in milliseconds between offset commits when ackMode is "TIME" or "COUNT_TIME".
spring.kafka.listener.concurrency= # Number of threads to run in the listener containers.
spring.kafka.listener.poll-timeout= # Timeout in milliseconds to use when polling the consumer.
spring.kafka.listener.batch-listener= # If true listener container factory will be configured to create batch listener.
spring.kafka.producer.acks= # Number of acknowledgments the producer requires the leader to have received before considering a request complete.
spring.kafka.producer.batch-size= # Number of records to batch before sending.
spring.kafka.producer.bootstrap-servers= # Comma-delimited list of host:port pairs to use for establishing the initial connection to the Kafka cluster.

Loading…
Cancel
Save