【问题标题】:Spring Kafka configure number of partitions for topicSpring Kafka 为主题配置分区数
【发布时间】:2019-01-11 01:21:08
【问题描述】:
是否可以在 Spring Kafka 中为特定主题配置分区数,以便能够有效地使用org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory.setConcurrency(Integer) 方法来并行处理该主题的消费者,以加快消息的消费和处理速度?如果是这样,请您举例说明如何做到这一点。
【问题讨论】:
标签:
spring-boot
apache-kafka
spring-kafka
【解决方案1】:
见Configuring Topics。
@Bean
public NewTopic topic1() {
return new NewTopic("foo", 10, (short) 2);
}
将创建一个主题 foo,其中包含 10 个分区和复制因子 2(如果应用程序上下文中有 KafkaAdmin bean)。
Spring boot 自动配置一个KafkaAdmin@Bean。