如何使用Spring DSL处理带Camel的zip文件?

时间:2013-08-22 10:12:55

标签: apache-camel

我想监视zip文件的目录,然后使用Camel和Spring DSL单独处理zip文件中的文件。有类似以下内容吗?

<camel:route>
  <camel:from uri="file:/src/Path/"/>
  <camel:split streaming="true">
    <zipSplit/>
    <camel:to uri="bean:fileProcessor?method=processStream"/>
  </camel:split>
</camel:route>

好的,所以我发现以下内容适用于包含一个文件的zip文件,但问题是如何处理包含多个文件的zip文件?

<bean id="zipFileDataFormat" class="org.apache.camel.dataformat.zipfile.ZipFileDataFormat"/>

<camel:camelContext>
    <camel:contextScan/>
    <camel:route>
        <camel:from uri="file:///C:/testSrc/?delay=6000&noop=true&idempotent=false"/>
        <camel:unmarshal ref="zipFileDataFormat"/>
        <camel:to uri="file:///C:/testDst"/>
    </camel:route>
</camel:camelContext>

请注意,该文件未被发送到bean以进行处理,只是解压缩到另一个目录中。

1 个答案:

答案 0 :(得分:5)

这很有效。请注意,log元素将为您提供详细信息。

<bean id="zipFileDataFormat" class="org.apache.camel.dataformat.zipfile.ZipFileDataFormat">
    <property name="usingIterator" value="true"/>
</bean>

<camel:camelContext>
    <camel:contextScan/>
    <camel:route id="unzipMultipleFiles">
        <camel:from uri="file:///C:/testSrc/?delay=30000&amp;noop=true&amp;idempotent=false"/>
        <camel:unmarshal ref="zipFileDataFormat"/>
        <camel:split streaming="true">
            <camel:simple>${body}</camel:simple>
            <camel:to uri="log:org.apache.camel?level=INFO&amp;showAll=true&amp;multiline=true"/>
            <camel:to uri="file:///C:/testDst"/>
        </camel:split>
    </camel:route>
</camel:camelContext>