远程目录为空时,Spring Integration Flow API不响应 [英] Spring Integration Flow API does not response when empty remote directory

查看:166
本文介绍了远程目录为空时,Spring Integration Flow API不响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring Integration SFTP协议在远程入站和出站服务器上传输文件.当我的远程入站服务器目录包含任何文件时,它工作正常,但是当我的远程服务器目录为空意味着没有文件时,它没有响应.我正在使用以下代码

IntegrationFlows.from(Sftp.inboundAdapter(inboundSftp)
            .localDirectory(this.getlocalDirectory(config.getId()))
            .deleteRemoteFiles(true)
            .autoCreateLocalDirectory(true)
            .filter(new CompositeFileListFilter().addFilter(new LastModifiedLsEntryFileListFilter(config.getRegexFilter())))
            .remoteDirectory(config.getInboundDirectory())
            , e -> e.poller(Pollers.cron(config.getCron())
                    .errorChannel(MessageHeaders.ERROR_CHANNEL).errorHandler((ex) -> {
    })))

我只想输入控制台日志消息,这样当有空的远程目录时,它必须说空的远程目录"或找不到文件". 我在这个问题上浪费了很多时间,没有发现任何富有成果的东西.请帮我,有什么办法可以检查directory.empty()并打印出我们的消息.

Sftp.inboundAdapter(inboundSftp)是基于轮询器配置的计划任务的SourcePollingChannelAdapter.如果没有来自源的数据来构建消息,则它实际上不会对outputChannel产生任何作用.但关键是触发任务仍然执行,并且我们对如何捕获该阶段有一些了解.

为此,我们为其afterReceive()实现提供了AbstractMessageSourceAdvice组件.在这里您可以执行空远程目录"逻辑.然后必须将这样的Advice注入poller(Pollers...advice())中.

在文档中查看更多信息: https://docs.spring.io/spring-integration/docs/5.3.0.M4/reference/html/core.html#conditional-pollers

I am using spring integration SFTP protocol to transfer files on remote inbound and outbound servers.It works fine when my remote inbound server directory contains any file but it does not response when my remote server directory is empty means there is no file.I am using following piece of code

IntegrationFlows.from(Sftp.inboundAdapter(inboundSftp)
            .localDirectory(this.getlocalDirectory(config.getId()))
            .deleteRemoteFiles(true)
            .autoCreateLocalDirectory(true)
            .filter(new CompositeFileListFilter().addFilter(new LastModifiedLsEntryFileListFilter(config.getRegexFilter())))
            .remoteDirectory(config.getInboundDirectory())
            , e -> e.poller(Pollers.cron(config.getCron())
                    .errorChannel(MessageHeaders.ERROR_CHANNEL).errorHandler((ex) -> {
    })))

I just want to put on console log message such that when there is empty remote directory it must says that Empty Remote Directory or No Files Found. I have wasted a lot of my time on this issue and nothing is fruitful thing found. Please help me is there any way we can check that directory.empty() and prints our message.

解决方案

The Sftp.inboundAdapter(inboundSftp) is a SourcePollingChannelAdapter based on a scheduled task according poller configuration. It really produces nothing into an outputChannel if there is no data from the source to build a message. But the point is that a task on trigger is still performed and we have some hooks how to catch that phase.

For this purpose we have an AbstractMessageSourceAdvice component for its afterReceive() implementation. This is a place where you can perform your "Empty Remote Directory" logic. Such an Advice then has to be injected in the poller(Pollers...advice()).

See more info in Docs: https://docs.spring.io/spring-integration/docs/5.3.0.M4/reference/html/core.html#conditional-pollers

这篇关于远程目录为空时,Spring Integration Flow API不响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆