我有一个集成案例,从FTP获取xml有效负载然后使用http出站通道将有效负载发送到webservice,ftp inbound-channel-adapter有一个名为local-directory的强制属性,远程ftp文件将在这里下载,但是当我重新启动时,似乎将再次处理本地目录中的所有文件,我可以知道如何避免这种情况吗? 一种可能的方法是删除ftp inbound-channel-adapter中的本地文件,怎么做,你能建议吗?
感谢
My Spring集成配置
<ftp:inbound-channel-adapter
channel="requestChannel"
session-factory="ftpClientSessionFactory"
remote-directory="/outbound"
local-directory="/temp"
auto-create-local-directory="true"
delete-remote-files="false"
filename-pattern="*.xml"
temporary-file-suffix=".writing">
<int:poller fixed-delay="5000" max-messages-per-poll="10"/>
</ftp:inbound-channel-adapter>
<int:chain id="inboundChain" input-channel="requestChannel" output-channel="replyChannel">
<int:transformer ref="xmlToJsonTransformer" />
<int:transformer ref="jsonToMapTransformer" />
<int:header-enricher>
<int:header name="Content-Type" value="application/json" overwrite="true"/>
</int:header-enricher>
<http:outbound-gateway expected-response-type="java.lang.String"
url="http://localhost:8080/postService/postupdate"
http-method="POST"
extract-request-payload="true"
request-factory="requestFactory">
</http:outbound-gateway>
</int:chain>
答案 0 :(得分:1)
将ExpressionEvaluatingRequestHandlerAdvice
添加到出站网关以删除该文件。有关示例,请参阅Expression Evaluating Advice Demo in the retry-and-more sample - 它会删除或重命名文件,具体取决于成功与否。
答案 1 :(得分:1)
感谢Gray的建议,这是我更正的配置
<int:chain id="inboundChain" input-channel="requestChannel" output-channel="replyChannel">
<int:header-enricher>
<int:header name="file_originalFile" expression="payload"/>
<int:header name="file-name" expression="payload.name"/>
<int:header name="file-failed-path" value="/project/ftp/failed/"/>
<int:header name="Content-Type" value="application/json" overwrite="true"/>
</int:header-enricher>
<int:transformer ref="xmlToJsonTransformer" />
<int:transformer ref="jsonToMapTransformer" />
<http:outbound-gateway expected-response-type="java.lang.String"
url="http://localhost:8080/postService/postupdate"
http-method="POST"
extract-request-payload="true"
request-factory="requestFactory">
<http:request-handler-advice-chain>
<bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
<property name="onSuccessExpression" value="headers['file_originalFile'].delete()" />
<property name="onFailureExpression"
value="headers['file_originalFile'].renameTo(new java.io.File(headers['file-failed-path']+headers['file-name']))"/>
</bean>
</http:request-handler-advice-chain>
</http:outbound-gateway>