我在名为“test-files”的S3存储桶中有以下文件夹结构:
pending-files/products
pending-files/prices
每个文件夹包含许多小型CSV文件,我想在一次调用中检索它们,然后处理For Each循环中的每个文件,其中包含一个Choice组件,用于根据文件夹名称重定向有效负载,例如: “产品”或“价格”。
我使用列表对象来检索文件,并且能够检索所有文件,但列表中包含该文件夹的条目,并且由于该文件夹不是有效的CSV文件,For Each将无法验证,并且还会失败空文件检查,因为大小将为0。
我该怎么做?
XML工作流程:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:s3="http://www.mulesoft.org/schema/mule/s3" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/s3 http://www.mulesoft.org/schema/mule/s3/current/mule-s3.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<flow name="listobjects">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="1000" timeUnit="HOURS"/>
<s3:list-objects config-ref="Amazon_S3__Configuration" bucketName="test-files" prefix="pending-files/" maxKeys="5" doc:name="Amazon S3" delimiter="/" marker="pending-files/"/>
</poll>
<foreach collection="#[payload.objectSummaries]" doc:name="For Each">
<logger message="#[payload.getKey()]" level="INFO" doc:name="Logger"/>
<s3:get-object-content config-ref="Amazon_S3__Configuration" bucketName="test-file-drop" key="#[payload.getKey()]" mimeType="application/csv" doc:name="Amazon S3"/>
<choice doc:name="Choice">
<when expression="">
<flow-ref name="csvToMongodbFlow" doc:name="csvToMongodbFlow"/>
</when>
<otherwise>
<logger message="#['*************Missed*****************']" level="INFO" doc:name="Logger"/>
</otherwise>
</choice>
</foreach>
<logger message="#['\nCompleted']" level="INFO" doc:name="Logger"/>
</flow>
</mule>