Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do <int-sftp:inbound-channel-adapter id="sftpInbondAdapte> programatically

i try to change from xml to programatically configuration one example from spring-boot integration which is SftpInboundReceiveSample

These are my configurations :
SftpPoller

@Configuration
public class SftpPoller{

@Autowired
SftpInboundFileSynchronizer sFtpInboundFileSynchronizer;

@Bean
@InboundChannelAdapter(value = "receiveChannel",poller = @Poller(fixedRate = "1000",maxMessagesPerPoll = "1"))
MessageSource<File> pollFtpForFiles() {

    SftpInboundFileSynchronizingMessageSource messageSource = new SftpInboundFileSynchronizingMessageSource(sFtpInboundFileSynchronizer);
    messageSource.setLocalDirectory(new File("local-dir"));
    messageSource.setAutoCreateLocalDirectory(true);

    return messageSource;
}
@Bean
PollableChannel receiveChannel() {return new QueueChannel();}
}

FtpConfiguration

@Configuration
@ImportResource("META-INF/spring/integration/SftpSampleCommon.xml")
@PropertySource("classpath:/application.properties")
public class SftpConfiguration {

    @Autowired
    @Qualifier("serverPort")
    String serverPort;

    @Value("${privateKeyfile}")
    Resource privateKeyfile;
    ...

    @Bean
    DefaultSftpSessionFactory defaultSftpSessionFactory() {
        DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory();
        factory.setHost(host);
        factory.setPrivateKey(privateKeyfile);
        factory.setPrivateKeyPassphrase(passphrase);
        .....
        return factory;
    }

    @Bean
    CachingSessionFactory cachingSessionFactory(DefaultSftpSessionFactory defaultSftpSessionFactory) {
        return new CachingSessionFactory(defaultSftpSessionFactory);
    }

    @Bean
    SftpInboundFileSynchronizer sftpInboundFileSynchronizer(CachingSessionFactory cachingSessionFactory) {
        final SftpInboundFileSynchronizer sftpInboundFileSynchronizer = new SftpInboundFileSynchronizer(cachingSessionFactory);
        sftpInboundFileSynchronizer.setRemoteDirectory("remote-dir");
        sftpInboundFileSynchronizer.setDeleteRemoteFiles(false);
        return sftpInboundFileSynchronizer;
    }
}

SftpInboundReceiveSample.java

@Test
public void runDemo() {
    //load context
    AnnotationConfigApplicationContext context = 
       new AnnotationConfigApplicationContext(SftpConfiguration.class, SftpPoller.class);
    ....

    try{
        PollableChannel localFileChannel = 
                context.getBean("receiveChannel", PollableChannel.class);
        ....

        // cant find SourcePollingChannelAdapter
        SourcePollingChannelAdapter adapter =
                context.getBean(SourcePollingChannelAdapter.class); -

        adapter.start();
        ....
}

Question :

  1. Where can i find SourcePollingChannelAdapter or should I look for different 'PollingChannelAdapter' ?
  2. Is it possible to move all configurations inside xml (except SftpSampleCommon.xml) to POJO? and how ?

thank you for any help and assistance.

like image 368
slawalata Avatar asked Apr 27 '26 20:04

slawalata


1 Answers

  1. You have to add @EnableIntegration on the @Configuration. That's is the main annotation to bootstrap Spring Integration infrastructure.

  2. The SourcePollingChannelAdapter doesn't exist because of the @EnableIntegration absence.

  3. Looks like you already did everything in the Java Config! :-)

  4. You even can move that SftpSampleCommon.xml to the Java Config as well.

Please, read more about Spring Integration Annotation Support and pay attention to the Spring Integration Java DSL project.

like image 93
Artem Bilan Avatar answered May 01 '26 00:05

Artem Bilan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!