定义多个 kafkaComponent bean 时,Kafka Camel Spring Boot AutoConfiguration 不会被拾取 [英] Kafka Camel Spring Boot AutoConfiguration is not picked up when multiple kafkaComponent beans are defined

查看:32
本文介绍了定义多个 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 不会被拾取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆