Spring used kafka

Add dependent

Maven quoted dependence

<!-- kafka -->
<dependency>
    <groupId>org.springframework.kafka</groupId>
    <artifactId>spring-kafka</artifactId>
</dependency>

Graden The following example shows how to operate Gradle:

compile 'org.springframework.kafka:spring-kafka'

Creating topic

        KafkaTemplate when sent has helped us to complete the operation creates, so we do not need to take the initiative to create a Topic, but referred KafkaTemplate to complete. But this is also a problem, created out of this situation Topic Partition (partition) number is always only one, there will not be a copy (do not know remake recycled, used when Kafka deploy clusters), which led to the we can not successfully expand at a later stage. So this case we need to use the manual code to create Topic.

 @Bean
 public NewTopic topic() {
    return new NewTopic("topic1", 3, (short) 1);
}
//创建TopicName为topic1的Topic并设置分区数为3以及副本数为2  dlt为死信队列
@Bean
public NewTopic dlt() {
    return new NewTopic("topic1.DLT", 3, (short) 2);
}

        We want to increase the number of partitions late to improve the system throughput, so we need to change the number of partitions of the Topic. Implementation is very simple, only need to modify the second argument we just wrote topic () method, you can immediately restart the project. Modify the number of partitions and does not result in loss of data, but only increase the number of partitions can not be reduced.

 



 

 

Reference: https: //www.jianshu.com/p/aa196f24f332

Published 74 original articles · won praise 18 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_40826106/article/details/104105542