我在camel-kafka-starter
依赖项中使用Kafka组件。
在此question中,建议我使用“定制程序”。我将如何在Spring Boot应用程序中使用它?
答案 0 :(得分: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
该组件随后将流入此定制程序并在那里进行处理。