简体   繁体   中英

Return file content from Camel route using exchange

Im using FluentProducerTemplate to send some data into Camel route and getting back hardcoded string message "Hello". Now I want Camel route to return data from text or json file which is stored locally. I couldn't find in a documentation how route should return the file content. I assume it should be something as exchange.getIn().setBody(<declare path>) but Im not sure how to do/declare it. I would have that file in a project's IDE folder/package dataOut/data.txt .

@EndpointInject
private FluentProducerTemplate producer;

public String getDataFromRoute(Employee employee){
    String strData = producer.withBody(employee)
           .to("direct:invokeRoute")
           .request(String.class);
    return strData;      
}

@Override
public void configure() throws Exception {
     from("direct:invokeRoute")
            .process(exchange -> {
                 exchange.getIn().setBody("Hallo")
        });
}

In your route you need to do a enrichment.

https://camel.apache.org/components/3.4.x/eips/pollEnrich-eip.html

public void configure() throws Exception {
     from("direct:invokeRoute")
      .pollEnrich("file:dataOut?fileName=data.txt");
}

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