kafka设置分区

avatar
作者
猴君
阅读量:0
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);     }   } 

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

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!