我想保存来自localhost(json data)示例的内容:
"id": 1,
"prename": "Noel",
"surname": "Reyes",
"dateOfBirth": "1988-09-07",
"birthPlace": "Bad Ems",
"gender": "M"}在文件夹(Example.txt中为C:\inputFolder)中)。这是我的代码:
from("timer://foo?period=5s")
.to("http4://localhost:8091/customers/")
.log("Test3 ${body}")
.to("file:C:/inputFolder/Example.txt");
但是:我的route1是从本地主机启动并使用的,但它没有将其保存在文本文件中。
main] DefaultCamelContext INFO Apache Camel 2.22.2 (CamelContext: camel-1) is starting
[ main] ManagedManagementStrategy INFO JMX is enabled
[ main] DefaultTypeConverter INFO Type converters loaded (core: 195, classpath: 15)
[ main] HttpComponent INFO Created ClientConnectionManager org.apache.http.impl.conn.PoolingHttpClientConnectionManager@24c4ddae
[ main] DefaultCamelContext INFO StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
[ main] DefaultCamelContext INFO Route: route1 started and consuming from: timer://foo?period=5s
[ main] DefaultCamelContext INFO Total 1 routes, of which 1 are started
[ main] DefaultCamelContext INFO Apache Camel 2.22.2 (CamelContext: camel-1) started in 2.945 seconds
Process finished with exit code 0你能帮帮我吗?
发布于 2018-11-30 17:24:18
我认为你的代码一切都很好。这可能是数据不在文本文件中的原因。在http操作之后,您正在记录正文,并且一旦记录的正文内容消失。
from("timer://foo?period=5s")
.to("http4://localhost:8091/customers/")
.convertBodyTo(String.class)
.log("Test3 ${body}")
.to("file:C:/inputFolder/Example.txt")我认为在日志记录之前将body转换为string convertBodyTo(String.class)可以解决这个问题。
https://stackoverflow.com/questions/53545766
复制相似问题