2

I'd like to utilize Spring Integration to initiate messages about files that appear in a remote location, without actually transferring them. All I require is the generation of a Message with, say, header values indicating the path to the file and filename.

What's the best way to accomplish this? I've tried stringing together an FTP inbound channel adapter with a service activator to write the header values I need, but this causes the file to be transferred to a local temp directory, and by the time the service activator sees it, the message consists of a java.io.File that refers to the local file and the remote path info is gone. It is possible to transform the message prior to this local transfer occurring?

4

1 回答 1

2

我们有类似的问题,我们用过滤器解决了它。在入站通道适配器上,您可以设置自定义过滤器实现。因此,在轮询之前,您的过滤器将被调用,您将获得有关文件的所有信息,您可以从中决定是否下载该文件,例如;

<int-sftp:inbound-channel-adapter id="test"
                                  session-factory="sftpSessionFactory"
                                  channel="testChannel"
                                  remote-directory="${sftp.remote.dir}"
                                  local-directory="${sftp.local.dir}"
                                  filter="customFilter"
                                  delete-remote-files="false">
    <int:poller trigger="pollingTrigger" max-messages-per-poll="${sftp.max.msg}"/>
</int-sftp:inbound-channel-adapter>

<beans:bean id="customFilter" class="your.class.location.SftpRemoteFilter"/>

Filter 类只是 FileListFilter 接口的实现。这是虚拟过滤器实现。

public class SftpRemoteFilter implements FileListFilter<LsEntry> {

    private static final Logger log = LoggerFactory.getLogger(SftpRemoteFilter.class);

    @Override
    public final List<LsEntry> filterFiles(LsEntry[] files) {
       log.info("Here is files.");
       //Do something smart
       return Collections.emptyList();
    }
}

但是,如果您想按照您的描述执行此操作,我认为可以通过在有效负载上设置标头,然后在使用该有效负载时使用相同的标头来做到这一点,但在这种情况下,您应该Message<File>在服务激活器方法中改用 File .

于 2014-09-15T16:12:19.483 回答