Mule ESB:在sftp连接器中添加<service-overrides messagereceiver =“myReceiver”>不起作用</service-overrides>

时间:2013-12-12 07:28:53

标签: mule

我使用mule处理来自sftp的文件,但我需要按顺序处理文件(序列按文件名顺序)。
例如: sftp中有3个文件:
的1.txt,2.txt,3.txt
我需要逐个处理这三个文件,并且必须按文件名的顺序。(首先处理1.txt然后2.txt到最后3.txt)
我在连接器中使用service-overrides并扩展SftpMessageReceiver并覆盖poll()方法,在方法中我按顺序创建这些文件的名称。但它不起作用。谁能告诉我哪里出错了。
我写的班级

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();
    }
}

}

配置文件如下

<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>
像吹气一样流动

<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 个答案:

答案 0 :(得分:1)

您的消息接收器未被调用的原因是您有一个调用SFTP传输的Quartz端点,因此实际上您使用的是消息请求者,而不是接收者。

您需要创建自定义消息请求者而不是接收者以及自定义请求者工厂(创建请求者的实例)

您可以按如下方式对其进行配置:

<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>