【发布时间】:2016-05-25 03:36:09
【问题描述】:
感谢关注
我在我的项目中使用了 spring 集成,我想从多个具有不同地址的 ftp 服务器检索许多输入文件,如下图所示:
如何在我的项目中动态创建inbound-adapter 以从服务器轮询和检索文件?
【问题讨论】:
标签: java spring spring-integration spring-batch esb
感谢关注
我在我的项目中使用了 spring 集成,我想从多个具有不同地址的 ftp 服务器检索许多输入文件,如下图所示:
如何在我的项目中动态创建inbound-adapter 以从服务器轮询和检索文件?
【问题讨论】:
标签: java spring spring-integration spring-batch esb
如果您被允许在您的项目中使用非“通用”(GA) 版本的 3rd 方库(例如候选版本 (RC) 或里程碑 (M)),那么您可以使用版本 5.0.0.M2弹簧集成。它是截至 2017 年 3 月 9 日的最新 published 版本。
从5.0开始,Spring Integration 包含Java DSL Runtime 流注册功能。它允许您定义集成流(包括入站适配器),就像在标准 bean 中一样,但它可以在任何运行时完成。
您只需要使用这 3 个步骤:
IntegrationFlowContext bean,例如通过自动装配: @Autowired
public MyClass(IntegrationFlowContext flowContext) {
this.flowContext = flowContext;
}
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
IntegrationFlowContext:// 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);
GitHub 上还有一个DynamicTcpClient sample。
【讨论】:
请参阅dynamic-ftp sample。虽然它只涵盖出站端,但 README 中有一些链接可以讨论入站端需要做什么(将每个适配器放在子上下文中,将消息发送到主上下文中的通道)。
另请参阅我对similar question for multiple IMAP mail adapters using Java configuration 和follow-up question 的回答。
你应该能够使用那里使用的技术。
【讨论】: