Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
328 views
in Technique[技术] by (71.8m points)

java - how dynamic create ftp adapter in spring integration?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...