java - 用camel处理2个不同的文件

标签 java kotlin apache-camel camel-ftp

我如何使用camel(使用ftp)读取两个不同的文件并编写唯一的JSON? 据我所知,“来自”只能读取一个文件。

from("ftp://myftp@localhost:21" +
                "/myFolder/" +
                "?" +
                "password=RAW(myPassword)" +
                "&include=file1.txt" +
                "&passiveMode=true" +
                "&delete=true")
            .log("Connected to FTP 1")

最佳答案

我认为您需要的是一个 pollEnrich 模式,如下所示:

from("ftp:...&include=file1.txt...")
    .log("Connected to FTP 1")
    .pollEnrich("ftp:...&include=file2.txt...", new MyFileAggregationStrategy() )

或者,如果您需要指定动态文件名,如下所示:

from("ftp:...&include=file1.txt...")
    .log("Connected to FTP 1")
    .pollEnrich().simple("ftp:...&include=${header.file2Name}...")
        .aggregationStrategy( new MyFileAggregationStrategy() )

您需要创建一个 AggregationStrategy ,这可以直接创建 JSON,也可以将输出发送到创建 JSON 的处理器。

您需要查看 pollEnrich 上的手册,以确保您正确处理如果 file1.txt 出现而没有相应的 file2.txt 时发生的情况,这样它就不会阻塞,除非您希望它阻塞(其中如果您需要能够在 AggregationStrategy 中处理 null)。

我希望这会有所帮助。

关于java - 用camel处理2个不同的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59155404/

相关文章:

java - 一个对象的多个实例的并发问题

android - WindowInsetsControllerCompat.OnControllableInsetsChangedListener 不会在插图显示操作上触发

java - 在 Kotlin 中覆盖 Java @Nullable varargs 方法,IDE 提示它没有覆盖任何内容

android - Firebase Unresolved reference

web-services - 使用简单的 Camel 代理传播 SOAPFault

apache-camel - Apache Camel 拆分和聚合异常处理

apache-camel - 在 Apache Camel 中以 UTC 格式格式化当前日期和时间

Java:在 Eclipse 中导出到 .jar 文件

java - 如何在 xp 和 windows 7 上运行 SWT 应用程序

Javafx无法加载新添加的图像