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)
;
我没有使用 Simple 语言来操作主体,而是调用主体并向其附加一个 \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屋!