Apache camel process(processor) 方法没有被调用

Apache camel process(processor) method is not being called

我在另一个 post 中看到手动添加 camel 上下文并启动它应该如何工作,但它不适合我。我仔细检查了 from 和 to 路径,它们似乎是正确的。不确定为什么不调用该方法,希望得到一些建议

public class CsvRouteBuilder extends DdsRouteBuilder {
  private CsvConverterProcessor csvConverterProcessor;
  private CamelContext camelContext;
  @Autowired
  public CsvRouteBuilder(CsvConverterProcessor csvConverterProcessor) throws Exception {
    this.csvConverterProcessor = csvConverterProcessor;
    camelContext.addRoutes(new RouteBuilder() {
      @Override
      public void configure() throws Exception {
        from("{{input.files.csv}}")
            .routeId("CSVConverter")
            .process(new Processor() {
              @Override
              public void process(Exchange exchange) throws Exception {
                System.out.println("hitting");
              }
            })
            .to("{{output.files.csv}}");
      }
    });
    camelContext.start();

  }

处理器未被调用仅仅是因为您的路由未正确声明,因此 Spring 引导无法识别它。

正确的方法是让你的 class 扩展 RouteBuilder to define your route(s) and annotate your class with @Component 以在使用 annotation-based 配置和 class 路径扫描时将其标记为 auto-detection 的候选者.

您的代码应该是这样的:

@Component
public class CsvRouteBuilder extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        from("{{input.files.csv}}")
            .routeId("CSVConverter")
            .process(new Processor() {
                @Override
                public void process(Exchange exchange) throws Exception {
                    System.out.println("hitting");
                }
            })
            .to("{{output.files.csv}}");
    }
}