【发布时间】:2014-12-03 12:03:47
【问题描述】:
我有一个条件,我应该通过以下步骤从 SFTP 远程位置读取文件:
从 SFTP 位置读取文件,例如
input文件夹。处理文件并使用文件内容调用 REST API。
如果调用成功,将远程 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的响应将远程文件移动到另一个远程位置?
【问题讨论】:
-
抱歉,你的场景看起来不错。你面临什么问题?删除或不删除远程文件对您没有意义,因为默认情况下
AcceptOnceFileListFilter用于本地文件。 -
实际上,在评估 API 调用响应后,一旦 API 调用成功,我想将远程文件移动到远程文件夹中的另一个位置。我的问题是如何根据
http:outbound-gateway的响应将远程文件移动到另一个远程位置? -
现在很清楚了。您之前没有具体说明问题……Gary 的回答适合您吗?
-
http:outbound-gateway响应后,我如何从singleFile频道获取文件?并根据文件名如何将 sftp 位置的文件从一个文件夹移动到另一个文件夹? -
我编辑了我的答案;以后请尽量详细说明您的问题。
标签: java spring spring-integration