Kafka Camel Spring Boot AutoConfiguration is not picked up when multiple kafkaComponent beans are defined(定义多个 kafkaComponent bean 时,Kafka Camel Spring Boot AutoConfiguration 不会被拾取)
问题描述
我目前正在使用 这个 camel-kafka-startermaven 依赖 在 Spring Boot 中自动配置我的 kafka camel 组件.
I'm currently using this camel-kafka-starter maven dependency to autoconfigure my kafka camel component in Spring Boot.
如果我添加说,像这样的设置 camel.component.kafka.configuration.linger-ms=20
.Camel kafka 组件在路由中拾取它,我可以在日志输出中看到它的配置值.例如
If I add say, a setting like this camel.component.kafka.configuration.linger-ms=20
. The camel kafka component picks it up in the route and I can see its config value in the log output.
e.g.
@Component
public class route extends RouteBuilder {
@Override
public void configure() throws Exception {
from("file://target/inbox")
.to("kafka:topic?brokers=localhost:9092");
}
}
现在,如果我定义另一个 camelKafkaComponent Bean,它会丢失自动配置!我希望它能够保持 application.propeties 中定义的设置...
Now, if i define another camelKafkaComponent Bean, it loses the autoconfiguration! I'd expect it to maintain the settings defined in application.propeties...
@Configuration
public class MyConfiguration {
@Bean
public KafkaComponent myKafkaComponent() {
return new KafkaComponent(); //missing the linger-ms=20 i set in application.properties!
}
@Component
public class route extends RouteBuilder {
@Override
public void configure() throws Exception {
from("file://target/inbox")
.to("myKafkaComponent:topic?brokers=localhost:9092");
}
}
}
有没有办法通过一些设置来维护自动配置,例如
Is there a way to maintain the autoconfiguration by some setting e.g.
myKafkaComponent.useAutoConfig()
理想情况下,在我的 application.properties 中,我有大约 40 多个设置,我想将它们转移到我的用户定义的骆驼 kafkaComponent.是否有必要创建另一个 Config 类并映射骆驼文档中定义的所有这些值?(带有类似 String @Value 注释的东西)
Ideally in my application.properties I'd have ~40+ settings that I would like to just transfer over to my user defined camel kafkaComponent. Is it necessary to create another Config class and map all those values defined in the camel docs? (with something like String @Value annotations)
我在看 源代码 并且想知道是否有办法在我的 bean 定义中调用它.
edit: I was looking at the source code and was also wondering if there was a way to call it inside my bean definition.
推荐答案
你可以创建一个类型的bean
You can create a bean of type
ComponentCustomizer<KafkaComponent>
可用于自定义camel自动配置的kafka组件
which can be used to customize the kafka component auto configured by camel
这篇关于定义多个 kafkaComponent bean 时,Kafka Camel Spring Boot AutoConfiguration 不会被拾取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:定义多个 kafkaComponent bean 时,Kafka Camel Spring Boot AutoConfiguration 不会被拾取


- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01