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.
I had to do something similar. This following works in camel 2.18+ -
rest("/load")
.get("/sampleFile")
.to("direct:readFromSampleFile")
;
from("direct:readFromSampleFile")
.pollEnrich("file://c:/folder?fileName=sample.txt&noop=true&idempotent=false") // idempotent to allow re-read, no-op to keep the file untouched
.convertBodyTo(String.class)
.log("Read ${body}")
.unmarshal().json(JsonLibrary.Jackson)
.setHeader("Content-Type").constant("application/json")
.log("Returned ${body}")
;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With