0

Hi I am pretty new to spring and trying to fetch the files from sftp server using SFTP inbound channel adapter in java config but unable to close the adapter ,I tried using the below code snippet, But Main isn't recongizing the inbound adapter and so adapter.start() and adapter.stop(); are NOT working . Please provide me any working example of closing the InboundChannelAdapter.

public SftpInboundFileSynchronizer sftpInboundFileSynchronizer() {
   SftpInboundFileSynchronizer fileSynchronizer = new SftpInboundFileSynchronizer(sftpSessionFactory());
   fileSynchronizer.setDeleteRemoteFiles(false);
   fileSynchronizer.setRemoteDirectory(sftpFolder);
   fileSynchronizer.setFilter(new SftpSimplePatternFileListFilter("*.pdf"));
   return fileSynchronizer;

}

@Bean
@InboundChannelAdapter(channel = "stream",poller = @Poller(fixedDelay ="5000",maxMessagesPerPoll = "1"),autoStartup="false")
public MessageSource<File> sftpMessageSource() {
   SftpInboundFileSynchronizingMessageSource source = new SftpInboundFileSynchronizingMessageSource(
           sftpInboundFileSynchronizer());
   source.setLocalDirectory(new File("ftp-inbound"));
   source.setAutoCreateLocalDirectory(true);
   source.setLocalFilter(new AcceptOnceFileListFilter<File>());
   return source;

}

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

}

@Bean
@ServiceActivator(inputChannel = "stream")
public MessageHandler handler() {

   return new MessageHandler() {

      @Override
         public void handleMessage(Message<?> message) throws MessagingException {
            System.out.println("payload"+ message.getPayload());
            //System.out.println(""+message.);

         }

   };
}

@Bean
@ServiceActivator(inputChannel = "controlBusChannel")
public ExpressionControlBusFactoryBean controlBus() throws Exception {
    ExpressionControlBusFactoryBean controlBus = new ExpressionControlBusFactoryBean();
    return controlBus;
}
4

0 回答 0