简体   繁体   English

Spring集成ftp-outbound-gateway,没有远程文件

[英]Spring integration ftp-outbound-gateway without no remote files

I have been working on spring integration <int-ftp:outbound-gateway> ,I was able to download files from remote server with ftp-outbound-gateway , But there is one problem I could not solve yet, If remote directory contains files the system works and will complete without any issues, but If there was no files system hang up without executing from that point.I want to continue the system. 我一直致力于spring integration <int-ftp:outbound-gateway> ,我能够使用ftp-outbound-gateway从远程服务器下载文件,但是有一个问题我还无法解决,如果远程目录包含文件系统工作并将完成没有任何问题,但如果没有文件系统挂起而没有从该点执行。我想继续系统。 whether remote folder contains files or not, 远程文件夹是否包含文件,

Here is the my Configuration for the ftp downloads 这是我的ftp下载配置

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:int="http://www.springframework.org/schema/integration"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:int-ftp="http://www.springframework.org/schema/integration/ftp"
       xsi:schemaLocation="http://www.springframework.org/schema/integration/ftp
        http://www.springframework.org/schema/integration/ftp/spring-integration-ftp.xsd
        http://www.springframework.org/schema/integration
        http://www.springframework.org/schema/integration/spring-integration.xsd
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

    <context:property-placeholder location="classpath:host.properties"/>

    <int:gateway id="gw" service-interface="com.util.ToFtpFlowGateway"
                 default-request-channel="inbound"/>

    <bean id="downloadProcessBean" class="com.util.FTPDownloadInterceptor">
        <property name="fileType" value="txt"/>
        <property name="sourceType" value="ftp"/>
        <property name="destinationName" value="destinationName"/>
        <property name="destinationQueName" value="destinationQueName"/>
        <property name="sourceAddressDetails" value="sourceAddressDetails"/>
        <property name="sourceName" value="sourceName"/>
    </bean>

    <bean id="ftpSessionFactory"
          class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
        <property name="host" value="${local.host}"/>
        <property name="port" value="${local.availableServerPort}"/>
        <property name="username" value="${local.userid}"/>
        <property name="password" value="${local.user.password}"/>
    </bean>

    <int-ftp:outbound-gateway id="gatewayLS" cache-sessions="false"
                              session-factory="ftpSessionFactory"
                              request-channel="inbound"
                              command="ls"
                              command-options=""
                              expression="payload"
                              reply-channel="toSplitter" reply-timeout="10" />

    <int:channel id="toSplitter">
        <int:interceptors>
            <int:wire-tap channel="logger"/>
        </int:interceptors>
    </int:channel>

    <int:logging-channel-adapter id="logger" log-full-message="true" />

    <int:splitter id="splitter" input-channel="toSplitter" output-channel="toGet"/>

    <int-ftp:outbound-gateway id="gatewayGET" cache-sessions="false"
                              local-directory="/home/udeshika/project/req/local/download"
                              session-factory="ftpSessionFactory"
                              request-channel="toGet"
                              reply-channel="toRemoveChannel"
                              command="get"
                              command-options="-P"
                              expression="payload.remoteDirectory + '/' + payload.filename" reply-timeout="10"/>

    <int-ftp:outbound-gateway id="gatewayRM"
                              session-factory="ftpSessionFactory" cache-sessions="false"
                              expression="payload.remoteDirectory + '/'+ payload.filename"
                              request-channel="toRemoveChannel"
                              command="rm"
                              reply-channel="aggregateResultsChannel"
                              auto-create-local-directory="true"
                              reply-timeout="10"

            />
    <!--<bean id="fileDownloadIntecepter" class="shipxpress.util.FTPDownloadInterceptor"/>-->
    <int:channel id="toRemoveChannel">
        <int:interceptors>
            <int:wire-tap channel="logger2"/>
            <!--<int:ref bean="fileDownloadIntecepter" />-->
        </int:interceptors>
    </int:channel>

    <bean class="org.springframework.integration.file.FileReadingMessageSource"
          p:directory="${download.directory}"/>

    <int:logging-channel-adapter id="logger2"  log-full-message="true" />

    <int-ftp:outbound-gateway id="gatewayRM"
                              session-factory="ftpSessionFactory" cache-sessions="false"
                              expression="headers['file_remoteDirectory'] + '/' + headers['file_remoteFile']"
                              request-channel="toRemoveChannel"
                              command="rm"
                              reply-channel="aggregateResultsChannel"/>

    <int:aggregator input-channel="aggregateResultsChannel"/>

</beans>

Could anyone help me to clear this, 任何人都可以帮我清除这个,

Thank you in advance Udeshika, 提前谢谢Udeshika,

The problem with this flow is the LS returns an empty list; 这个流程的问题是LS返回一个空列表; when this hits the splitter, it results in no messages and the flow stops. 当它击中分离器时,它不会产生任何消息,流量也会停止。 The thread that calls the gateway is waiting forever (by default) for a reply. 调用网关的线程将永远等待(默认情况下)进行回复。

Add a reply timeout to the gateway and it will return null if no response is received. 向网关添加回复超时,如果没有收到响应,则返回null。

<int:gateway id="gw" service-interface="org.springframework.integration.samples.ftp.ToFtpFlowGateway"
    default-request-channel="inbound" default-reply-timeout="100" />

As long as you use Direct channels, there's no danger of the gateway timing out when there's real work to do because the timer doesn't start until the thread returns to the gateway to look for any reply that was produced by the downstream flow. 只要您使用直接通道,当有真正的工作要做时,没有网关超时的危险,因为在线程返回到网关寻找下游流产生的任何回复之前,计时器才会启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM