[英]how dynamic create ftp adapter in spring integration?
如果允許您在項目中使用第三方庫的非“通用”(GA)版本(例如,發布候選版本(RC)或里程碑(M)),則可以使用Spring的5.0.0.M2
版本。積分。 它是截至17 Mar 09'的最新發布版本。
從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示例 。
請參閱dynamic-ftp示例 。 盡管它僅涵蓋出站方,但自述文件中有一些鏈接,可用於討論入站方需要做什么(將每個適配器置於子上下文中,該子上下文將消息發送到主上下文中的通道)。
另請參閱我對使用Java配置的多個IMAP郵件適配器的類似問題的回答,以及后續問題 。
您應該能夠使用那里使用的技術。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.