简体   繁体   中英

Apache camel process(processor) method is not being called

I saw in another post how manually adding the camel context and starting it should work, but it hasn't for me. I double checked the from, and to paths and they seem to be correct. Not sure why it's not calling the method and would appreciate some advice

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();

  }

The processor is not called simply because your route is not properly declared such that Spring Boot is not aware of it.

The proper way is to make your class extend RouteBuilder to define your route(s) and annotate your class with @Component to mark it as candidate for auto-detection when using annotation-based configuration and classpath scanning.

Your code should rather be something like this:

@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}}");
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM