Apache Camel Java DSL向正文添加换行符 [英] Apache Camel Java DSL add newline to body
问题描述
所以我在Java DSL中设置了一个netty4套接字路由,如下所示:
So I have a netty4 socket route set up in Java DSL that looks like the following:
@Override
public void configure() throws Exception {
String dailyDataUri = "{{SOCKET.daily.file}}" + "&fileName=SocketData-${date:now:yyyyMMdd}.txt";
from(socketLocation).routeId("thisRoute")
.transform()
.simple("${in.body}\n")
.wireTap(dailyDataUri)
.to(destination)
;
wireTap和目的地都将其数据发送到两个单独的文件.并且目标文件中的数据收集用\n
(换行符)分隔开...或者至少应该分隔开.
Where both the wireTap and the destination are sending their data to two separate files. And the data collection in the destination file is separated by a \n
(line break)... or at least it should be.
在查看创建的文件时,永远不会添加\n
.
When viewing the files created, the \n
is never added.
在我改用Java之前,Spring DSL中的等效想法已经起作用:
The equivalent idea in the Spring DSL worked before I switched to Java:
<transform>
<simple>${in.body}\n</simple>
</transform>
使用该选项并打开在路由期间创建的文件后,通过套接字输入的数据行将由换行符分隔.
After using that and opening the files created during the route, the lines of data that came in through the socket would be separated by a newline.
我在Java DSL中做错了什么,不允许将换行符随输入的数据添加到套接字数据中?
我觉得这很明显,我只是看不到.
I feel like it's something obvious that I just don't see.
传入的数据只是一个类似CSV的文本行.
The data that is coming in is just a CSV-like line of text.
推荐答案
我找到了一个解决方案,我不确定从Spring到Java几乎可以将每个单词翻译成什么.显然,转换/简单组合存在一些问题,在Java DSL中它不适用于我.
I found a solution, I'm never sure what can be translated almost word from word from Spring to Java. Apparently the transform/simple combination has some issue where it will not work for me in Java DSL.
因此可能的解决方案(可能会有更多解决方案)是这样做的:
So a possible solution (there may be more solutions) is to do this:
@Override
public void configure() throws Exception {
String dailyDataUri = "{{SOCKET.daily.file}}" + "&fileName=SocketData-${date:now:yyyyMMdd}.txt";
from(socketLocation).routeId("thisRoute")
.transform(body().append("\n"))
.wireTap(dailyDataUri)
.to(destination)
;
在这里,我没有调用简单语言来操纵主体,而是调用了主体,并在其后面附加了\n
字符串.这就解决了我的问题.
Where instead of using the Simple language to manipulate the body, I just call on the body and append a String of \n
to it. And that solves my issue.
这篇关于Apache Camel Java DSL向正文添加换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!