我有一个工作原型Spring Boot应用程序,它侦听Kafka队列。除了shared_ptr<int> sptr;
中的配置外,所需要的只是application.yml
使用MessageListener
注释的实现。
我现在介绍Spring Integration,并且已经配置了这些bean:
@KafkaListener
应用程序未启动,并且抛出此错误:
@Bean
public KafkaMessageDrivenChannelAdapter<String, String>
adapter(KafkaMessageListenerContainer<String, String> container) {
KafkaMessageDrivenChannelAdapter<String, String> kafkaMessageDrivenChannelAdapter =
new KafkaMessageDrivenChannelAdapter<>(container);
kafkaMessageDrivenChannelAdapter.setOutputChannel(receiver());
return kafkaMessageDrivenChannelAdapter;
}
@Bean
public KafkaMessageListenerContainer<String, String> container() throws Exception {
ContainerProperties properties = new ContainerProperties(this.topic);
// set more properties
return new KafkaMessageListenerContainer<>(consumerFactory(), properties);
}
@Bean
public ConsumerFactory<String, String> consumerFactory() {
Map<String, Object> props = ...; // set proerties
return new DefaultKafkaConsumerFactory<>(props);
}
即使我已经定义了Parameter 1 of method kafkaListenerContainerFactory in org.springframework.boot.autoconfigure.kafka.KafkaAnnotationDrivenConfiguration required a bean of type 'org.springframework.kafka.core.ConsumerFactory' that could not be found.
- Bean method 'kafkaConsumerFactory' in 'KafkaAutoConfiguration' not loaded because @ConditionalOnMissingBean (types: org.springframework.kafka.core.ConsumerFactory; SearchStrategy: all) found bean 'consumerFactory'
Action:
Consider revisiting the conditions above or defining a bean of type 'org.springframework.kafka.core.ConsumerFactory' in your configuration.
bean。
在调试模式下运行,很明显Boot正在加载一个ConsumerFactory
bean来监听代理:
KafkaListenerEndpointContainer
然后:
[org.springframework.kafka.KafkaListenerEndpointContainer#0-0-C-1] o.a.k.c.c.internals.AbstractCoordinator : Discovered coordinator localhost:9092 (id: 2147483999 rack: null) for group my_group.
我认为发生的事情是Spring Boot \ Kafa自动配置与Spring Integration \ Kafka设置发生冲突。解决这个问题的正确方法是什么?
由于
答案 0 :(得分:4)
您可以使用Boot的消费者工厂......
@Bean
public KafkaMessageListenerContainer<String, String> container(ConsumerFactory<String, String> cf) {
...
}
或禁用kafka自动配置
@SpringBootApplication(exclude = KafkaAutoConfiguration.class)