spring ftp integration使用' local-filename-generator-expression'

时间:2015-12-01 12:01:19

标签: spring-integration

我想从ftp读取文件并将其存储在本地存储为与根目录下的远程文件相同的路径(我需要它来处理文件)。 远程文件路径是动态的,并根据过滤器而变化。 (当service-activator调用方法拉动时)处理文件

<int:channel id="ftpChannel">
      <int:queue/>
</int:channel>

    <int-ftp:inbound-channel-adapter id="ftpInbound"
        channel="ftpChannel" session-factory="ftpSessionFactory"
        auto-create-local-directory="true" delete-remote-files="true"
        remote-directory="/"
        remote-file-separator="/" temporary-file-suffix=".writing"
        local-filename-generator-expression ="/+=#this"
        local-directory="${mfg.root.dir}">
        <int:poller fixed-rate="50000" />
    </int-ftp:inbound-channel-adapter>

     <bean id= "directoryFilter" class="il.co.mit.mfg.filter.FilterClass" scope="prototype" >
        <property name="channelType" value="****"/>
        <property name="rootFolder" value="${mfg.root.dir}"/>
    </bean>

    <int:channel id="pubSubChannel">
       <int:queue/>
   </int:channel>
    <int:channel id="output">
      <int:queue/>
     </int:channel>

    <file:inbound-channel-adapter id="inboundfolder"
        channel="pubSubChannel"
        directory="${mfg.root.dir}"
        prevent-duplicates="false">
    </file:inbound-channel-adapter>

    <int:poller default="true" fixed-delay="5000">
          <int:transactional transaction-manager="transactionManager"  />
    </int:poller>

    <int:service-activator id="inputFileServiceActivator"
        input-channel="pubSubChannel" method="pull" ref="typeAdapter" output-channel="output">
</int:service-activator>

    <bean id="ftpSessionFactory"
        class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
        <property name="host" value="*****" />
        <property name="port" value="21" />
        <property name="username" value="******" />
        <property name="password" value="******" />
        <property name="clientMode" value="0" />
        <property name="fileType" value="2" />
        <property name="bufferSize" value="100000" />
    </bean>

我一直在尝试使用local-filename-generator-expression,但我不确定如何编写SpEL表达式。 我是新来的,请帮忙

1 个答案:

答案 0 :(得分:0)

目前尚不清楚你的意思

  

远程文件路径是动态的,并根据过滤器进行更改。

远程路径是文字;过滤器无法改变它。

variable    labelstatement1 labelstatement2
q1p0    label define q1p0 1 "Yes " 2 "No "  label values q1p0 q1p0
q1p1    label define q1p1 1 "Yes " 2 "No "  label values q1p1 q1p1
q2p0    label define q2p0 1 "Yes " 2 "No "  label values q2p0 q2p0

如果您只是想要使用远程文件名作为本地文件名 - 这将是默认名称 - 只需省略remote-directory="/"

如果你真的想要动态路径而不是文件名,那么使用ftp outbound gateway会更好;在那里你可以完全控制远程和本地路径。