我有一个来自for-each的多条记录的字符串格式列表。我将它们传递给Batch进行拆分和处理,但它们仍作为单行写入到我的File组件中。 我已经使用表达式#[payload.split('\ n')]将字符串列表分成多行。请帮忙。下面是到目前为止的代码。
<mulerequester:config name="Mule_Requester" doc:name="Mule Requester"/>
<file:connector name="File" autoDelete="false" streaming="true" validateConnections="true" doc:name="File" outputAppend="true"/>
<flow name="inbound_Flow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/001" allowedMethods="GET" doc:name="HTTP"/>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[ def folder = "${file.interfaceInbound.path}";
def baseDir = new File(folder); //new folder
def fileList = baseDir.listFiles(); //list of file names
ArrayList<String> InboundFileList = new ArrayList<String>();
for(File file : fileList) {
if( file.isDirectory() == false && file.getName().startsWith("${file.pattern}")){
InboundFileList.add(file.getName());
}
}
message.setProperty('InboundFileList',InboundFileList,org.mule.api.transport.PropertyScope.INVOCATION);
if(InboundFileList.size() == 0){
message.setProperty('ZeroFiles',"No files available for processing",org.mule.api.transport.PropertyScope.INVOCATION);
throw new java.lang.Exception("No files available for processing");
}
]]></scripting:script>
</scripting:component>
<logger message="get valid file names from database" level="INFO" doc:name="Logger"/>
<db:select config-ref="Oracle_Configuration" doc:name="get file names">
<db:dynamic-query><![CDATA[select FILE_NAME from vdis_fin.PY_GL_FILES_TO_PROCESS]]></db:dynamic-query>
</db:select>
<foreach doc:name="For Each" collection="#[payload]">
<logger message="file payload #[payload]" level="INFO" doc:name="Logger"/>
<set-variable variableName="fileName" value="#[payload.FILE_NAME]" doc:name="fileName"/>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[def matchFound =false;
for(i in flowVars['InboundFileList']){
log.info("file name from DB:" +flowVars.fileName);
log.info("Files in folder:"+i);
if((flowVars['fileName'])== i)
{
matchFound=true;
break;
}
}
message.setProperty('matchFound',matchFound,org.mule.api.transport.PropertyScope.INVOCATION);
]]></scripting:script>
</scripting:component>
<logger message="#[flowVars.matchFound]" level="INFO" doc:name="Logger"/>
<choice doc:name="Choice">
<when expression="#[flowVars['matchFound']=='true']">
<logger message="file name #[flowVars.fileName] is valid" level="INFO" doc:name="Logger for valid"/>
<logger message="file path : ${file.interfaceInbound.path}${ils.filename}${ils.sourceExtension}" level="INFO" doc:name="Logger"/>
<mulerequester:request config-ref="Mule_Requester" resource="file:///${file.interfaceInbound.path}${ils.filename}${ils.sourceExtension}" doc:name="Mule Requester"/>
<object-to-string-transformer doc:name="Object to String"/>
<batch:execute name="inbound_flowBatch" doc:name="inbound_flowBatch"/>
</when>
<otherwise>
<logger message="file name #[flowVars.fileName] is not valid" level="INFO" doc:name="Logger"/>
</otherwise>
</choice>
</foreach>
</flow>
<batch:job name="inbound_flowBatch">
<batch:input>
<set-payload value="#[payload.split('\n').]" doc:name="Set Payload"/>
</batch:input>
<batch:process-records>
<batch:step name="Batch_Step1" >
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<file:outbound-endpoint path="${file.interfaceOutbound.path}" outputPattern="${file.Outbound.name}" responseTimeout="10000" doc:name="File" connector-ref="File"/>
</batch:step>
</batch:process-records>
<batch:on-complete>
<logger message="completed iteration" level="INFO" doc:name="Logger"/>
</batch:on-complete>
</batch:job>
</mule>