1
votes

I am working with a VERY large csv file and using Mule Requester to read the contents of the file. I have an ftp connector configured and have set the streaming to "true" but, when I try to log the payload, I can see the Mule Requester is returning a Byte Array which means it will load all the contents of the file into Memory and I don't want that.

Here's my flow:

        <?xml version="1.0" encoding="UTF-8"?>

    <mule xmlns:batch="http://www.mulesoft.org/schema/mule/batch" xmlns:mulerequester="http://www.mulesoft.org/schema/mule/mulerequester" xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" xmlns:ftp="http://www.mulesoft.org/schema/mule/ee/ftp" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" 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/ee/ftp http://www.mulesoft.org/schema/mule/ee/ftp/current/mule-ftp-ee.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
    http://www.mulesoft.org/schema/mule/mulerequester http://www.mulesoft.org/schema/mule/mulerequester/current/mule-mulerequester.xsd
    http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
    http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
    http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd
    http://www.mulesoft.org/schema/mule/batch http://www.mulesoft.org/schema/mule/batch/current/mule-batch.xsd">
        <ftp:connector name="FTP" pollingFrequency="1000" streaming="true" validateConnections="true" doc:name="FTP"/>
        <flow name="mulerequesterstreamFlow1" processingStrategy="synchronous">
            <quartz:inbound-endpoint jobName="streamingTest" repeatInterval="15000" responseTimeout="10000" doc:name="Quartz">
                <quartz:event-generator-job/>
            </quartz:inbound-endpoint>
            <flow-ref name="mulerequesterstreamFlow" doc:name="mulerequesterstreamFlow"/>
        </flow>
        <flow name="mulerequesterstreamFlow" processingStrategy="synchronous">
            <mulerequester:request resource="ftp://vagrant:[email protected]:21/home/vagrant/read_directory?connector=FTP" throwExceptionOnTimeout="true" doc:name="Mule Requester" />
            <choice doc:name="Choice">
                <when expression="#[payload != empty]">
                    <logger message="payload is not empty #[payload]" level="INFO" doc:name="Logger - payload"/>
                </when>
                <otherwise>
                    <logger message="empty payload" level="INFO" doc:name="Logger - log when payload is empty"/>
                </otherwise>
            </choice>
        </flow>
    </mule>

For simplicity, I've removed other logic that sits around these flows but wasn't necessary for this question.

Below is what gets logged:

payload is not empty [B@3ac94399
1
Why are you using a <quartz:inbound-endpoint> with a flow ref instead of a <ftp:inbound-endpoint> ?Pierre B.
For simplicity, I've removed other logic that sits around these flows but wasn't necessary for this question.swifty
The logic you are using may have transformed your payload into a Byte[] somewhere. Is there any logic between the mulerequester and the choice ?Pierre B.
Hi @PierreB. Nope, there's no logic between mulerequester and choice, therefore it shouldn't have converted the payload into Byte[]. The above flow works and logs the type of payload returned from Mule Requester which is of type Byte[].swifty

1 Answers

0
votes

whenever you trying to pass csv file then make sure that use transformer before choice scope and also in the choice scope drag another transformer and logger to get the result, mention the "when" condition of choice scope by reffering the transformer which you are using inside the choice scope flow and put the logger inside for each scope, so that it will iterate.make sure that don't put the transformer inside the foreach scope.