0
votes

I'm trying to use the outbound gateway to download files from sftp server, my config:

@IntegrationComponentScan
@EnableIntegration
@Configuration
public class FtpConfig {

@Bean(name = "myGateway")
@ServiceActivator(inputChannel = "sftpChannel")
public MessageHandler handlerLs() {
    SftpOutboundGateway sftpOutboundGateway = new SftpOutboundGateway(sftpSessionFactory(), "mget", "payload");
    sftpOutboundGateway.setLocalDirectory(new File("/Users/xxx/Documents/"));
    return sftpOutboundGateway;

}

@MessagingGateway
public interface OutboundGatewayOption {

    @Gateway(requestChannel = "sftpChannel")
    List<File> mget(String dir);

}

@Bean
public MessageChannel sftpChannel() {
    return new DirectChannel();
    }

}

and the execute bean:

@Service
public class DownloadService implements InitializingBean{

@Autowired
FtpConfig.OutboundGatewayOption gatewayOption;

@Override
public void afterPropertiesSet() throws Exception {

   List<File> files =  gatewayOption.mget("/sftp/server/path");
 }
}

and I got this exception:org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'application.sftpChannel'.; Qestion :how can I add the 'subscribers' ?

1

1 Answers

0
votes

You can't perform messaging operator in the afterPropertiesSet(). That's too early : some beans might not be initialized yet. And that exception confirms the problem.

You have to implement SmartLifecicle instead and do the same in the start().