alexanoid
alexanoid

Reputation: 25862

Spring Kafka configure number of partitions for topic

Is it possible in Spring Kafka configure the number of partitions for the specific topic in order to be able to effectively use org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory.setConcurrency(Integer) method to parallel consumers on this topic in order to speed up message consumptions and processing? If so, could you please show the example of how it can be done.

Upvotes: 7

Views: 5723

Answers (1)

Gary Russell
Gary Russell

Reputation: 174759

See Configuring Topics.

@Bean
public NewTopic topic1() {
    return new NewTopic("foo", 10, (short) 2);
}

Will create a topic foo with 10 partitions and a replication factor of 2 (if there is a KafkaAdmin bean in the application context).

Spring boot auto-configures a KafkaAdmin @Bean.

Upvotes: 6

Related Questions