英文:
Spring Boot for Kafka - Multiple KafkaStreams config in one app
问题
在 Spring 中,对于 Kafka Streams,我们可以在一个应用程序中定义两个配置吗?
如果我们有两个 @Bean
用于配置,就像这样,我该如何将 secondConfig
用于流处理?
@Configuration
@EnableKafkaStreams
public class KafkaStreamConfig {
@Bean(name = KafkaStreamsDefaultConfiguration.DEFAULT_STREAMS_CONFIG_BEAN_NAME)
public KafkaStreamsConfiguration kafkaStreamConfig() {
var props = new HashMap<String, Object>();
props.put(StreamsConfig.APPLICATION_ID_CONFIG, "kafka-stream");
props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
....
return new KafkaStreamsConfiguration(props);
}
@Bean(name = "secondConfig")
public KafkaStreamsConfiguration secondKafkaStreamConfig() {
var props = new HashMap<String, Object>();
props.put(StreamsConfig.APPLICATION_ID_CONFIG, "kafka-stream");
props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "other-machine:9092");
....
return new KafkaStreamsConfiguration(props);
}
}
谢谢
英文:
In spring for kafka stream can we define two configurations in one app?
If we have two @Bean
for config, like this, how can I use secondConfig
into the stream?
@Configuration
@EnableKafkaStreams
public class KafkaStreamConfig {
@Bean(name = KafkaStreamsDefaultConfiguration.DEFAULT_STREAMS_CONFIG_BEAN_NAME)
public KafkaStreamsConfiguration kafkaStreamConfig() {
var props = new HashMap<String, Object>();
props.put(StreamsConfig.APPLICATION_ID_CONFIG, "kafka-stream");
props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
....
return new KafkaStreamsConfiguration(props);
}
@Bean(name = "secondConfig")
public KafkaStreamsConfiguration kafkaStreamConfig() {
var props = new HashMap<String, Object>();
props.put(StreamsConfig.APPLICATION_ID_CONFIG, "kafka-stream");
props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "other-machine:9092");
....
return new KafkaStreamsConfiguration(props);
}
}
Thanks
答案1
得分: 1
Spring只会创建一个工厂bean(来自默认配置bean)。对于第二个工厂bean,您需要定义一个使用它的StreamsBuilderFactoryBean
。
英文:
Spring will only create one factory bean (from the default configuration bean). For the second one you will need to define a StreamsBuilderFactoryBean
that uses it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论