2017-09-15 69 views
1

是否有可能使用的Spring bean創建卡夫卡的話題。就像我們的隊列,並且可以創建編程像這些在RabbitMQ的TopicExchanges。創建卡夫卡的話題?

@Bean 
Queue queue(){ 
    return new Queue("name"); 
} 

試過文檔無法得到很多幫助。

回答

2

是的,現在可以使用最新的Spring卡夫卡版本1.3https://docs.spring.io/spring-kafka/docs/1.3.0.RC1/reference/html/_reference.html#_configuring_topics

@Bean 
public KafkaAdmin admin() { 
    Map<String, Object> configs = new HashMap<>(); 
    configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, 
      StringUtils.arrayToCommaDelimitedString(kafkaEmbedded().getBrokerAddresses())); 
    return new KafkaAdmin(configs); 
} 

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

但承擔,這是可能的,因爲Apache的卡夫卡0.11.0.x改進。