0

For my SFTP client project, I am using spring integration. We have different clients and have to connect to different SFTP servers, but, all of the logic is same, so I have abstracted them out into AbstractSFTPEndPoint. Each client-specific class implements getClientId(), which is used by AbstractSFTPEndPoint to get client-specific details like SFTP credentials.

However, the entire logic is same for all the clients, but I am still having to implement specific classes for each client. This is mainly because we need separate "MessageSource" for each client.

How can I get rid of this duplication?

public class SFTPEndPointForClientAAAA extends AbstractSFTPEndPoint {

    public String getClientId(){
       return "clientAAAA";
    }

    @Bean(name = "channelForClientAAAA")
    public QueueChannel inputFileChannel() {
        return super.inputFileChannel();
    }

    @ServiceActivator(inputChannel = "channelForClientAAAA", poller = @Poller(fixedDelay = "500"))
    public void serviceActivator(Message message) {
        super.serviceActivator(message);
    }

    @Bean(name = "messageSourceForClientAAAA")
    @InboundChannelAdapter(value = "channelForClientAAAA",
            poller = @Poller(fixedDelay = "50", maxMessagesPerPoll = "2"))
    public MessageSource messageSource() {
        return super.messageSource();
    }
}

Basically I have a bunch of SFTP hosts to connect to and apply same logic. I want that to be done automatically without having to implement class for each SFTP host.

coolscitist
  • 3,317
  • 8
  • 42
  • 59

1 Answers1

0

See the dynamic ftp sample. It uses XML but the same techniques apply to Java configuration. It uses outbound adapters; inbound are a little more complicated because you might need to hook them into a common context. There are links in the readme for how to do that.

However, I recently answered a similar question for multiple IMAP mail adapters using Java configuration and then a follow-up question.

You should be able to use the technique used there.

Community
  • 1
  • 1
Gary Russell
  • 166,535
  • 14
  • 146
  • 179