import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.clients.admin.NewTopic;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.core.KafkaAdmin;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@Configuration
public class KafkaTopicConfig {

    @Value("${kafka.topic.message}")
    private String topic;

    @Value("${spring.kafka.bootstrap-servers}")
    private String serverAddr;

    @Bean
    public NewTopic topicWithThreePartitions() {
        NewTopic newTopic = new NewTopic(topic, 2,(short)1);
        return newTopic;
    }

    @Bean
    public KafkaAdmin kafkaAdmin() {
        Map<String, Object> configs = new HashMap<>();
        configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG,serverAddr);
        return new KafkaAdmin(configs);
    }


}

声明一个配置文件就可以,这是设置了两个分区,一个副本

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部