Apache Camel PollEnrich:如何将文件体从花粉体解析为POJO以与初始文件聚合?

问题描述

我在使用Spring Boot应用程序和Apache骆驼时遇到以下情况:

  1. 从sftp读取csv文件
  2. 将其csv行广播到一个列表中,并用父POJO封装(父POJO拥有2个列表,其中1个用于步骤1的数据,第二个列表用于csv 2的数据(请参见步骤3)
  3. 从sftp服务器读取另一个csv文件
  4. 将其数据广播到列表中,并将其添加到步骤2中的原始父dto / exchange。
  5. 父POJO以列表形式包含所有数据,然后处理和转换数据
  6. 编组到xml并写入sftp服务器

第1步和第2步似乎有效,从我可以从骆驼文档中收集到的信息来看,现在我需要使用“ pollenrich”从sftp服务器加载第二个CSV文件。现在我遇到的问题是如何将文件2的数据与文件1的数据进行聚合。

我遇到以下问题:

    pollenrich的
  • 交换正文是一个远程文件。教程显示他们将其强制转换为File.class,这会引起排他性
  • 投完票后,如何加入两个交易所?

那么我该如何使用花粉来获取文件并将其数据添加到POJO?

我正在尝试类似: 路线:

this.from(CONNECTION_STRING_FILE1)
                .unmarshal(BINDY_ROW)
                .process(this.fileNameProcessor)
                .split(this.body(),this.dataAggregator)
                .bean(DataMapService.class,"mapData").end()
                .pollEnrich(CONNECTION_STRING_FILE2,this.metaDataAggregator)
                .process(this.xmlRootProcessor).marshal().jaxb()
                .to(CONNECTION_STRING_WRITE_OUTPUT);

FILENAMEPROCESSOR: 可行,结果是parentDto与包含file1中所有csv行的列表进行交换

@Service
public class FileNameProcessor implements Processor {

    private static final String OUTPUT_FILE_FORMAT = ".xml";

    @Override
    public void process(final Exchange exchange) throws Exception {
        String inputFileName = exchange.getIn().getHeader("CamelFileNameOnly").toString();
        inputFileName = inputFileName.substring(0,inputFileName.length() - 4);
        final String outputFileName = inputFileName + OUTPUT_FILE_FORMAT;
        exchange.getIn().setHeader("CamelFileNameOnly",outputFileName);

        final List<CrmCsvRow> crmCsvRowList = exchange.getIn().getBody(ArrayList.class);
        final ParentDto parent = new ParentDto();
        parent.setCsvRowList(crmCsvRowList);
        exchange.getIn().setBody(parent);
    }
}

METADATAAGGREGATOR:

@Service
@Slf4j
public class MetaDataAggregator implements AggregationStrategy {
    public Exchange aggregate(final Exchange oldExchange,final Exchange newExchange) {
        if (oldExchange == null) {
            return newExchange;
        }
        return this.aggregateData(oldExchange,newExchange);
    }

    private Exchange aggregateData(final Exchange oldExchange,final Exchange newExchange) {
       // Cast fails,saying it is a remote file cannot cast,but internet tutorials show this line of code working
        final File file = newExchange.getIn().getBody(File.class);
        // cast to POJO and add to "oldExchange" body
       // ... <HELP NEEDED>
        return oldExchange;
    }
}

通常,我将需要知道如何在聚合器中访问file2的数据,以便处理完整的父dto。

我们非常感谢您的帮助!

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)