javaapache-camelenterprise-integration

How to call Camel route that reads file?


I have camel route to read a file as below:

@Component
public class MessageRoute extends RouteBuilder {

    public static final String ROUTE_ID = "message.route";
    public static final String ROUTE_URI = "{{message.route.uri}}";

    @Override
    public void configure() throws Exception {

        from("file:://target/test.txt")
                .convertBodyTo(String.class)
                .process(exchange -> {
                    log.info("Body {}", exchange.getIn().getBody(String.class));
                });
    }
}

Now, the question is how to make a call to this route? My end goal is to call from producerTemplate and process the file content.

I couldn't find anything about this on Camel Docs

Also, I tried to use pollEnrich as mentioned in this answer, but while debugging, execution doesn't get there at all to aggregator.

I would be million dollars thankful for Any solution, suggestion or idea.


Solution

  • I was actually trying to call this route from another route or cascade it within a route. I found this working:

    public static final String FILE_ROUTE_ID = "file.route";
    public static final String FILE_ROUTE_URI = "{{file.route.uri}}";
    
    @Override
    public void configure() throws Exception {
    
        from(FILE_ROUTE_URI)
                .routeId(FILE_ROUTE_ID)
                .log(LoggingLevel.INFO, "Header {}", String.valueOf(simple("${header.purpose}")))
                .from("file:apache-camel-spring-boot?fileName=printing.key&noop=true")
                .convertBodyTo(String.class)
                .process(exchange -> {
                    log.info("Processing file . . .");
                    KeyBody keyBody = new KeyBody(exchange.getIn().getBody(String.class));
                    exchange.getIn().setBody(keyBody);
                });
    }
    

    Thank you all for looking into this!! Cheers!