Spring Functions Catalog 5.0.0‐M1 已釋出

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

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

我們剛剛將 5.0.0-M1 釋出到 https://repo.spring.io/milestone 倉庫,您只需要將此 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 通道介面卡 提供自動配置。

以下是一些示例

  • sftpSupplier 連線到 SFTP 伺服器並從遠端目錄輪詢檔案,並將檔案“提供”給您的應用程式
  • kafkaPublisher (java.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 是來自 FunctionCatalogRunnable,並且是上面提到的 application.yml 中的組合。該應用程式每秒在經過一些轉換後將當前時間傳送到日誌中。

嘗試一下 Spring Functions Catalog,歡迎任何反饋或貢獻!

從這裡開始,我們將在 3 月底推出 RC1,並在 4 月推出 GA

有關 Spring Functions Catalog 的更多資訊,請參見 GitHub 儲存庫

乾杯,+ Artem

獲取 Spring 新聞簡報

透過 Spring 新聞簡報保持聯絡

訂閱

領先一步

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

瞭解更多

獲得支援

Tanzu Spring 在一個簡單的訂閱中為 OpenJDK™、Spring 和 Apache Tomcat® 提供支援和二進位制檔案。

瞭解更多

即將舉行的活動

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

檢視全部