【问题标题】:How to split a file into lines in Camel but process the first line differently如何在骆驼中将文件拆分为行但以不同方式处理第一行
【发布时间】:2013-01-06 18:54:50
【问题描述】:

我正在使用分词器将文件分成几行:

.split().tokenize("\n", 1)

但是,我需要处理的一些文件将包含一个标题行,这将需要以不同于正常行的方式处理。有没有一种简单的方法可以读取第一行,对其进行处理,然后拆分剩余的行?

【问题讨论】:

    标签: apache-camel


    【解决方案1】:

    你可以做这样的事情。它将使用基于内容的路由器 EIP,然后使用不同的子路由进行处理。

    from(A)
       .split().tokenize("\n",1)
           .choice()
             .when(simple("${property.CamelSplitIndex} > 0"))
               .to("direct:processLine")
             .otherwise()
               .to("direct:processHeader");
    
    from("direct:processLine")
     .bean(processLineBean)
     .to(B);
    
    from("direct:processHeader")
     .bean(processHeaderBean)
     .to(B);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-27
      • 2011-12-11
      相关资源
      最近更新 更多