Spring Functions Catalog 5.0.0-M1 已釋出

釋出 | Artem Bilan | 2024 年 3 月 1 日 | ...

我代表 Spring Cloud Dataflow 團隊,很高興向大家介紹 Spring Functions Catalog。該專案的主要重點是提供一組獨立的 Java 函式,這些函式可以直接在終端使用者應用程式中使用。所有釋出的工件本質上是針對某些特定的 SupplierFunctionConsumer 的自動配置。

我們剛剛在 https://repo.spring.io/milestone 倉庫中釋出了 5.0.0-M1,您只需要將此 BOM 新增到您的 Gradle(或 Maven)配置中

org.springframework.cloud.fn:spring-function-dependencies:5.0.0-M1

併為您的專案選擇相應的功能作為依賴。

Spring Functions Catalog 是 Stream Applications 專案的 functions 子模組的品牌重塑(也是下一代)。這就是我們一開始就選擇版本號為 5.0 的原因,因為本專案中的所有功能都與 Stream Applications 中的功能相同。因此,我們接下來的自然步驟是將 Stream Applications 遷移到使用這個新的 Spring Functions Catalog。

然而,Spring Functions Catalog 的目標不僅僅是為 Stream Applications 提供支援。因為它們都是用於具有特定任務的單個 SupplierFunctionConsumer 的自動配置的獨立工件,所以這些功能可以直接新增到類路徑中,並在目標專案中按原樣使用,或者與其他任務組合使用。其中許多功能都為特定的 Spring Integration Channel Adapter 提供了自動配置。

以下僅舉幾例

  • sftpSupplier 連線到 SFTP 伺服器,輪詢遠端目錄中的檔案,並將這些檔案“提供”給您的應用程式
  • kafkaPublisherjava.util.function.Consumer 實現)將記錄釋出到 Apache Kafka 主題
  • aggregatorFunction 根據某個相關鍵將多個輸入分組為一個

在自動配置到 ApplicationContext 後,這些功能可以被注入到目標服務中,並使用純 Java API 進行組合(參見 Function.andThen(Function))。然而,更佳(也更適合 Spring 應用程式)的方式是利用 Spring Cloud Function 專案的功能。例如,可以使用 Spring Cloud Function Integration 模組中的 FunctionFlowBuilder 來為任何複雜的解決方案組合 IntegrationFlow。另一種方法是透過 spring.cloud.function.definition 配置屬性按名稱組合它們。

作為概念驗證,專案倉庫中的 time-spel-log 示例具有這些依賴項

implementation 'org.springframework.cloud.fn:spring-time-supplier'
implementation 'org.springframework.cloud.fn:spring-spel-function'
implementation 'org.springframework.cloud.fn:spring-log-consumer'

application.yml 具有此屬性

spring:
  cloud:
    function:
      definition: timeSupplier|spelFunction|logConsumer

應用程式邏輯如下所示

@Scheduled(fixedDelay = 1000)
void scheduleFunctionCall() {
  this.composedFunction.run();
}

其中 composedFunction 是來自 FunctionCatalog 的一個 Runnable,並且是在 application.yml 中提到的組合。該應用程式每秒將當前時間經過一些轉換後輸出到日誌中。

試試 Spring Functions Catalog,任何反饋或貢獻都歡迎!

從這裡,我們將在三月底邁向 RC1,並在四月釋出 GA

有關 Spring Functions Catalog 的更多資訊,請參閱 GitHub 倉庫

祝好, + Artem

獲取 Spring 新聞通訊

透過 Spring 新聞通訊保持聯絡

訂閱

領先一步

VMware 提供培訓和認證,助您加速進步。

瞭解更多

獲得支援

Tanzu Spring 提供 OpenJDK™、Spring 和 Apache Tomcat® 的支援和二進位制檔案,只需一份簡單的訂閱。

瞭解更多

即將舉行的活動

檢視 Spring 社群所有即將舉行的活動。

檢視所有