2
votes

Thanks for attention
i used spring integration in my project, i want to retrieve many input file from multiple ftp server with different address as bellow image: enter image description here

how to create dynamically inbound-adapter in my project to polling and retrieve files from servers?

2

2 Answers

1
votes

See the dynamic-ftp sample. While it only covers the outbound side, there are links in the README to discussions about what needs to be done on the inbound side (put each adapter in a child context that send messages to a channel in the main context).

Also see my answer to 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.

5
votes

If you're allowed to use non-"General Availability" (GA) versions of 3rd party libraries (e.g. release candidates (RC) or milestones (M)) in your project, then you can utilize version 5.0.0.M2 of Spring Integration. It is the latest published version as of Mar 09 '17.

Starting from 5.0, Spring Integration includes Java DSL Runtime flow registration feature. It allows you to define integration flows (including inbound adapters) just like you do it in standard beans but it can be done at any runtime moment.

All you need to use it are these 3 steps:

  1. Get IntegrationFlowContext bean from Spring context, e.g. by means of autowiring:
  @Autowired
  public MyClass(IntegrationFlowContext flowContext) {
    this.flowContext = flowContext;
  }
  1. Build new flow with it, for example:
  IntegrationFlowRegistration registration = flowContext
      .registration(IntegrationFlows   // this method accepts IntegrationFlow instance
                        .from(s -> s.ftp(ftpSessionFactory())
                                    .localFilter(localFileFilter())
                        //other actions
                        .get())        // standard end of DSL flow building process
      .autoStartup(true)               // not required but can be useful
      .register();                     // this makes the flow exist in the context
  1. When it's time to remove dynamically created flow, just refer to IntegrationFlowContext again with registration id you've got in the previous step:
// retrieve registration ID from the object created above
String dynamicFlowRegistrationId = registration.getId();
// the following will also gracefully stop all the processes within the flow
flowContext.remove(dynamicFlowRegistrationId);

There is also a DynamicTcpClient sample available on GitHub.