简体   繁体   English

如何使用Spring Integration DSL进行Ftp轮询

[英]how to do Ftp polling with Spring integration DSL

I am trying to create Dynamic ftp inbound adapters for the flow described below 我正在尝试为下面描述的流程创建动态ftp入站适配器

<int-ftp:inbound-channel-adapter id="ftpInbound"
    channel="ftpChannel" session-factory="ftpClientFactory"
    filename-pattern="*.txt" auto-create-local-directory="true"
    delete-remote-files="false" remote-directory="${remotedir}"
    local-directory="/mock/test" auto-startup="true">
    <int:poller fixed-rate="1000">
        <int:transactional synchronization-factory="syncFactory" />
    </int:poller>
</int-ftp:inbound-channel-adapter>

To do this I have created the below flows with SI java dsl that I register using SI dynamic registration as below 为此,我使用SI动态注册创建了以下SI Java dsl流,如下所示:

public void createSubFlows(FtpConfig config) {

    DefaultFtpSessionFactory sf = new DefaultFtpSessionFactory();
    Connection connection = config.getConnection();
    Feed feed = config.getFeed();
    sf.setHost(connection.getHost());
    sf.setPort(connection.getPort());
    sf.setUsername(connection.getUsername());
    sf.setPassword(connection.getPassword());

    IntegrationFlow flow = IntegrationFlows
            .from(Ftp.inboundAdapter(csf).preserveTimestamp(true)
                    .remoteDirectory(feed.getRemoteDirectory())
                    .regexFilter(".*\\.txt$")                   
                    .localDirectory(new File(feed.getLocalDirectory())),
                    e -> e.id("ftpInboundAdapter" + connection.getId()
                            + feed.getId())//
            ).handle(m -> System.out.println(m.getPayload())).get();
    this.flowContext.registration(flow)
    .id("ftp.flow" + connection.getId() + feed.getId()).autoStartup(true)
            .register();
}

The same works well but I wanted to also configure a dynamic poller similar to the one in the xml above . 相同的方法很好用,但是我还想配置一个动态轮询器,类似于上面的xml。 Is it possible to do the same with SI Java DSL 是否可以对SI Java DSL进行同样的操作

UPDATE 更新

Looks like it works though not sure why it doesnt come in the content assist 尽管不确定为什么它没有出现在内容帮助中,但看起来似乎可行

e -> e.poller(Pollers.fixedRate(100).maxMessagesPerPoll(1))

Are you sure that e in the .from() doesn't have .poller()`: 你肯定e.from()没有.poller()`:

   from(Ftp.inboundAdapter(csf)
          .preserveTimestamp(true)
                .remoteDirectory(feed.getRemoteDirectory())
                .regexFilter(".*\\.txt$")                   
                .localDirectory(new File(feed.getLocalDirectory())),
                e -> e.id("ftpInboundAdapter" + connection.getId()
                        + feed.getId()
              .poller())

?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM