簡體   English   中英

如何在Spring集成中動態創建ftp適配器?

[英]how dynamic create ftp adapter in spring integration?

感謝您的關注
我在項目中使用了spring集成,我想從具有不同地址的多個ftp服務器檢索很多輸入文件,如下所示: 在此處輸入圖片說明

如何在我的項目中動態創建inbound-adapter以輪詢和從服務器檢索文件?

如果允許您在項目中使用第三方庫的非“通用”(GA)版本(例如,發布候選版本(RC)或里程碑(M)),則可以使用Spring的5.0.0.M2版本。積分。 它是截至17 Mar 09'的最新發布版本。

5.0開始,Spring Integration包含Java DSL Runtime流注冊功能 就像在標准Bean中一樣,它允許您定義集成流(包括入站適配器),但是可以在任何運行時進行。

您只需使用以下3個步驟即可:

  1. 從Spring上下文中獲取IntegrationFlowContext bean,例如通過自動裝配:
  @Autowired
  public MyClass(IntegrationFlowContext flowContext) {
    this.flowContext = flowContext;
  }
  1. 用它構建新的流程,例如:
  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. 當需要刪除動態創建的流時,只需再次使用上一步中獲得的注冊ID再次參考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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM