viruskimera
viruskimera

Reputation: 208

Spring FTP inbound Channel Adapter - need to log in only every 5 min

I have the following code in my FTP Inb Channel Adptr, the company is telling me that I'm logging in every second...

public static void main(String[] args) {
        SpringApplication.run(FtpinboundApp.class, args);
    }

    @Bean
    public SessionFactory<FTPFile> ftpSessionFactory() {
        DefaultFtpSessionFactory sf = new DefaultFtpSessionFactory();
        sf.setHost(remotehost);
        sf.setPort(remoteport);
        sf.setUsername(remoteuser);
        sf.setPassword(remotepassword);
        return sf;
    }

    @Bean
    @ServiceActivator(inputChannel = "data", adviceChain = "after")
    public MessageHandler handler() {
        return new MessageHandler() {

            @Override
            public void handleMessage(Message<?> message) throws MessagingException {
                try {
                    httpposthgfiles.getHGFilesfromRestful(message.getPayload().toString());
                    httppost990.get990fromRestful(message.getPayload().toString());

                } catch (IOException e) {
                    logger.error(e);
                } catch (Exception e) {
                    logger.error(e);
                }
            }
        };
    }

    @Bean
    public ExpressionEvaluatingRequestHandlerAdvice after() {
        ExpressionEvaluatingRequestHandlerAdvice advice = new ExpressionEvaluatingRequestHandlerAdvice();
        advice.setOnSuccessExpression("@template.remove(headers['file_remoteDirectory'] + headers['file_remoteFile'])");
        advice.setPropagateEvaluationFailures(true);
        return advice;
    }

    @Bean
    @InboundChannelAdapter(value = "stream", poller = @Poller(fixedRate = "1000"))
    public MessageSource<InputStream> ftpMessageSource() {

        FtpStreamingMessageSource messageSource = new FtpStreamingMessageSource(template(), null);

        messageSource.setRemoteDirectory(remotedirectory);
        messageSource.setFilter(filter());

        return messageSource;
    }

    public FileListFilter<FTPFile> filter() {
        CompositeFileListFilter<FTPFile> filter = new CompositeFileListFilter<>();
        filter.addFilter(new FtpSimplePatternFileListFilter("xxxx_aaa204*"));
        filter.addFilter(acceptOnceFilter());
        return filter;
    }

    @Bean
    public FtpPersistentAcceptOnceFileListFilter acceptOnceFilter() {
        FtpPersistentAcceptOnceFileListFilter filter = new FtpPersistentAcceptOnceFileListFilter(meta(), "xxxx_aaa204");
        filter.setFlushOnUpdate(true);
        return filter;
    }

    @Bean
    public ConcurrentMetadataStore meta() {
        PropertiesPersistingMetadataStore meta = new PropertiesPersistingMetadataStore();
        meta.setBaseDirectory("/tmp/foo");
        meta.setFileName("ftpStream.properties");
        return meta;
    }

    @Bean
    @Transformer(inputChannel = "stream", outputChannel = "data")
    public org.springframework.integration.transformer.Transformer transformer() {
        return new StreamTransformer("UTF-8");
    }

    @Bean
    public FtpRemoteFileTemplate template() {
        return new FtpRemoteFileTemplate(ftpSessionFactory());
    }

    @Bean(name = PollerMetadata.DEFAULT_POLLER)
    public PollerMetadata defaultPoller() {
        PollerMetadata pollerMetadata = new PollerMetadata();
        pollerMetadata.setTrigger(new PeriodicTrigger(600_000));
        return pollerMetadata;
    }

why? is this cause I have:

@InboundChannelAdapter(value = "stream", poller = @Poller(fixedRate = "1000

??? In my understanding setting:

pollerMetadata.setTrigger(new PeriodicTrigger(300_000));

would make me log every 5 min?

and The fixedRate = "1000 would make me take the next file every second...

Upvotes: 0

Views: 547

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121292

Since you use fixedRate there, you don't use that PollerMetadata.DEFAULT_POLLER, there fore you connect to the FTP really each second.

The @Poller and PollerMetadata.DEFAULT_POLLER are really represents the same entity and mutually exclusive.

The logging into FTP and file downloading are happened at the same session. So, no difference for the target FTP server.

Upvotes: 1

Related Questions