我实现了一个 sftp-inbound-channel-adapter,当处理异常时,我应该显示一条自定义消息。
我试过 :
<int-sftp:inbound-channel-adapter id="sftpInbondAdapter"
auto-startup="true" channel="receiveChannel" session-factory="sftpSessionFactory"
local-directory="file:${directory.files.local}" remote-directory="${directory.files.remote}"
auto-create-local-directory="true" delete-remote-files="true"
filename-pattern="*.txt" >
<int:poller fixed-delay="${sftp.interval.request}"
max-messages-per-poll="-1" />
<int-sftp:request-handler-advice-chain>
<bean: class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
<property name="onSuccessExpression" value="payload" />
<property name="successChannel" ref="afterSuccessDeleteChannel" />
<property name="onFailureExpression" value="payload.renameTo(new java.io.File(payload.absolutePath + '.failed.to.send'))" />
<property name="failureChannel" ref="afterFailRenameChannel" />
</bean>
</int-sftp:request-handler-advice-chain>
但是一个元素
<int-sftp:request-handler-advice-chain>
不被接受。你能解释另一种解决方案吗?
最佳答案
请求处理程序建议在某个下游组件上运行,而不是在入站 channel 适配器上。
您可以添加 error-channel
到 <poller/>
元素。发送到错误 channel 的消息将是 ErrorMessage
除了作为有效载荷。如果是下游流的异常,则有效载荷将为 MessagingException
与 failedMessage
和 cause
特性。
添加一些组件来使用错误消息。
关于spring-integration - spring 集成 : inbound channel adapter. 捕获异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34678588/