1
votes

I use mule to process the files from sftp, but I need to process the file in order(the sequence is order by name of file).
For example: there are 3 files in sftp:
1.txt,2.txt,3.txt
I need to process these three files one by one and have to in the order of file's name.(first to process 1.txt then 2.txt at last 3.txt)
I use service-overrides in connector and extend the SftpMessageReceiver and override the poll() method ,in the method I make these files's name by order. But it doesn't work.Who can tell me where is wrong.
the class I write

public class NewSftpMessageReceiver extends SftpMessageReceiver {
private SftpReceiverRequesterUtil sftpRRUtil = null;


public NewSftpMessageReceiver(SftpConnector connector,
                              FlowConstruct flow,
                              InboundEndpoint endpoint,
                              long frequency) throws
                                              CreateException {
    super(connector, flow, endpoint);


    this.setFrequency(frequency);


    sftpRRUtil = new SftpReceiverRequesterUtil(endpoint);
}


public NewSftpMessageReceiver(SftpConnector connector, FlowConstruct flow, InboundEndpoint endpoint)
        throws
        CreateException {
    super(connector, flow, endpoint);
    sftpRRUtil = new SftpReceiverRequesterUtil(endpoint);
}


@Override
public void poll() throws
                   Exception {
    try {
        String[] files = sftpRRUtil.getAvailableFiles(false);

        //do something here.....
        for (String file : files) {
            if (getLifecycleState().isStopping()) {
                break;
            }
            routeFile(file);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

}

the config file like below

<sftp:connector name="incoming-mandate-connector"
                archiveDir="${esb.archive.path}/mandate/incoming"
                useTempFileTimestampSuffix="true"
                autoDelete="true"
                identityFile="${esb.incoming.sftp.identityFile}"
                passphrase="${esb.incoming.sftp.passphrase}"
                sizeCheckWaitTime="${esb.incoming.sftp.sizeCheckWaitTime}">
    <service-overrides messageReceiver="com.xxy.NewSftpMessageReceiver"/>        
</sftp:connector>


<sftp:endpoint name="incoming-mandate-ep"
               address="${esb.incoming.connector}"
               connector-ref="incoming-mandate-connector"
               keepFileOnError="true" encoding="${esb.encoding}">
    <file:filename-wildcard-filter pattern="${esb.incoming.filePattern}"/>
</sftp:endpoint>

the flow like blew

<flow name="process">


    <quartz:inbound-endpoint name="quartz-endpoint" cronExpression="${esb.cronExpression}" jobName="incoming-mandate-job">
        <quartz:endpoint-polling-job>
            <quartz:job-endpoint ref="incoming-mandate-ep"/>
        </quartz:endpoint-polling-job>
    </quartz:inbound-endpoint>



    <processor ref="mandate-processor"/>
    <transformer ref="mandate-transformer"/>
    <mulexml:jaxb-object-to-xml-transformer jaxbContext-ref="jaxb" name="mandate-jaxb-transformer"/>
    <byte-array-to-string-transformer mimeType="application/xml"/>

    <message-properties-transformer scope="outbound">
        <add-message-property key="${esb.username}" value="${esb.password}"/>
    </message-properties-transformer>
    <outbound-endpoint ref= "mandate-service-ep"/>
</flow>
1
Can you post the full configuration? Also add a logger to the custom receiver to see if it's called or not.Seba
I tried adding a logger to the custome receiver ,but there is no log print(I mean it is not called).I don't know where I am wrong.(I use mule3.2.0)xxy
There's still missing configuration.Seba
could you tell me missing which configuration ?xxy
The flow for example.Seba

1 Answers

1
votes

The reason why your message receiver is not being called is because you have a Quartz endpoint that calls the SFTP transport, so in fact you are using a message requester, not a receiver.

You would need to create a custom message requester instead of a receiver and also a custom requester factory (that creates instances of the requester)

You can configure it as follows:

<sftp:connector name="sftpConnector">
<spring:property name="serviceOverrides">
<spring:map>
<spring:entry key="requester.factory" value="your.package.YourCustomSftpRequesterFactory"/>
</spring:map>
</spring:property>
</ftp:connector>