我如何自定义预定义的骆驼组件?

问题描述 投票:0回答:1

我正在camel-kafka-starter依赖项中使用Kafka组件。建议在此question中使用“定制程序”。我将如何在Spring Boot应用程序中使用它?

java spring-boot apache-camel
1个回答
0
投票

解决方案是这样定义SpringBoot配置文件中的组件:

@Configuration
public class MyConfig {

   @Bean 
   ComponentCustomizer<KafkaComponent> myCustomizer(){
       return new ComponentCustomizer<KafkaComponent>() {

           @Override
           public void customize(KafkaComponent component) {
               //KafkaConfiguration config = new KafkaConfiguration(); //optional extra config

               component.setAllowManualCommit(true);
               component.setBrokers(brokers);
               component.setWorkerPool(workerPool); 
           };
       };
    }

   @Component
   public class route extends RouteBuilder {

        @Override
        public void configure() throws Exception {
           from("file://target/inbox")
           .to("direct:kafka_in")

           from("direct:kafka_in")
           .log(LoggingLevel.WARN, "Generated : $simple{body}")
           .to("kafka:topic2")
           .log("[P-kafka_in] regular Producer");

       } 
    }
}

除了在属性中设置的任何配置:

camel.component.kafka.configuration.retries=1234567
camel.component.kafka.configuration.request-required-acks=all
camel.component.kafka.configuration.enable-idempotence=true   

然后组件将流入此定制程序,并在那里进行处理。

© www.soinside.com 2019 - 2024. All rights reserved.