使用exchange从Camel路由返回文件内容



我使用FluentProducerTemplate发送一些数据到Camel路由并返回硬编码字符串消息"Hello"。现在我想骆驼路由返回数据从文本或json文件存储在本地。我在文档中找不到路由应该如何返回文件内容。我认为它应该是exchange.getIn().setBody(<declare path>),但我不知道如何做/声明它。我会将该文件放在项目的IDE文件夹/包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")
});
}

在你的路由中你需要做一个富集。

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