2014-12-03 121 views
2

我有一个条件,我应该通过以下步骤读取SFTP远程位置的文件后,远程SFTP位置移动文件:从SFTP位置Spring集成:处理

  1. 阅读文件说input文件夹。

  2. 处理文件并使用文件的内容调用REST API。

  3. 如果调用成功将遥控SFTP文件archive 文件夹其他远程SFTP文件移动到文件夹error

我想到了两种方法。我不知道哪一个可能。

首先,将文件从SFTP远程位置读取到本地并从远程删除。然后调用REST API。根据REST调用的响应,成功或错误将文件上传到远程文件夹。

其次,将文件从SFTP远程位置读取到本地。然后调用REST API。根据REST调用的响应,成功或错误将文件上传到远程文件夹。

任何人都可以启发我哪种方法可行和方便吗?如果您能提及通道适配器,我将不胜感激。

到目前为止,我可以调用REST API。

<int-sftp:inbound-channel-adapter id="sftpInbondAdapter" 
     auto-startup="true" 
     channel="receiveChannel" 
     session-factory="sftpSessionFactory" 
     local-directory="${local.dir}" 
     remote-directory="${sftp.dir.input}" 
     auto-create-local-directory="true" 
     delete-remote-files="true" 
     filename-pattern="*.txt"> 
     <int:poller fixed-rate="60000" max-messages-per-poll="1" /> 
    </int-sftp:inbound-channel-adapter> 
    <int:channel id="receiveChannel"/> 

    <int:splitter input-channel="receiveChannel" output-channel="singleFile"/> 
    <int:channel id="singleFile"/> 

    <int:service-activator input-channel="singleFile" 
     ref="sftpFileListenerImpl" method="processMessage" output-channel="costUpdate" /> 
    <int:channel id="costUpdate" /> 

    <int:header-enricher input-channel="costUpdate" output-channel="headerEnriched"> 
     <int:header name="content-type" value="application/json" /> 
    </int:header-enricher> 
    <int:channel id="headerEnriched" /> 

    <int-http:outbound-gateway 
     url="${cost.center.add.rest.api}" request-channel="headerEnriched" 
     http-method="POST" expected-response-type="java.lang.String" reply-channel="costAdded" > 
    </int-http:outbound-gateway> 
    <int:publish-subscribe-channel id="costAdded" /> 

我想移动远程文件到另一个位置在远程文件夹一次API调用是评估API调用响应之后的成功。我的问题是如何根据http:outbound-gateway的响应将远程文件移动到另一个远程位置?

+0

对不起,你的场景看起来不错。你面临什么问题?删除或不删除远程文件并不会让你感兴趣,因为默认情况下'AcceptOnceFileListFilter'就是用于本地文件的。 – 2014-12-03 12:32:11

+0

实际上,我想在评估API调用响应后,将API调用成功后,将远程文件移动到远程文件夹中的另一个位置。我的问题是,如何根据“http:outbound-gateway”的响应将远程文件移动到另一个远程位置? – nebula 2014-12-03 15:04:14

+0

现在很清楚。你没有在......之前指定具体问题吗?Gary的答案是否适合你? – 2014-12-03 15:06:14

回答

1

查看retry-and-more sample,特别是Expression Evaluating Advice Demo - 它显示了如何基于上传成功/失败采取不同的操作。

编辑:

在回应阿尔乔姆的回答您的意见;既然你有delete-remote-files="true"没有远程文件可以移动,您必须先将其设置为false

然后,按照我的建议使用建议来处理成功或失败 - 使用远程文件的ftp:outbound-gatewaymv。请参阅gateway documentation for the mv command

+0

我可以通过SFTP使用ftp:outbound-gateway吗? – nebula 2014-12-03 15:50:15

+0

是的;有[SFTP版本](http://docs.spring.io/spring-integration/reference/html/sftp.html#sftp-outbound-gateway)。在提问之前查阅文档通常是一个好主意。 – 2014-12-03 15:51:42

+0

谢谢。尽管我有最后一个困惑。在该通道之后,我有特定的文件直到'singleFile'通道,在其他后续通道中不会有文件消息。当远程位置有多个文件时,如何根据“http:outbound-gateway”的响应知道从远程文件夹移动哪个文件? – nebula 2014-12-03 16:06:17