最新動態?

2.0 版本自 1.2 版本以來的新功能

本節涵蓋從 1.2 版本到 2.0 版本的更改。

Spring Retry 被 Core Retry 取代

所有 Spring Retry 的使用都被 Spring Framework 最近引入的更簡單的重試機制取代。

這主要是重新啟動訊息容器時使用的內部實現細節。只有當您透過 `PulsarContainerFactoryCustomizer` bean 提供自定義的 `RetryTemplate` 時,才會受到影響。

`RetryTemplate` 類仍然存在於 Core Retry 中,但包名已從 `org.springframework.retry.support` 更改為 `org.springframework.core.retry`,並且 API 略有更改。

請參閱 提交 以獲取更多詳細資訊。

移除

先前已棄用的 API

以下先前已棄用且標記為在 2.0.x 版本中刪除的 API 現已刪除:

  • org.springframework.pulsar.config.ConcurrentPulsarListenerContainerFactory#setConcurrency

  • org.springframework.pulsar.config.ConcurrentPulsarListenerContainerFactoryCustomizer

  • org.springframework.pulsar.config.ListenerContainerFactory#createListenerContainer

  • org.springframework.pulsar.config.ReaderContainerFactory#createReaderContainer

  • org.springframework.pulsar.config.ProducerBuilderConfigurationUtil

  • org.springframework.pulsar.config.PulsarClientProxy#getPartitionsForTopic

  • org.springframework.pulsar.config.PulsarTopic#builder

  • org.springframework.pulsar.config.PulsarTopic#getFullyQualifiedTopicName

  • org.springframework.pulsar.config.Resolved#get

  • org.springframework.pulsar.test.support.model.UserPojo

  • org.springframework.pulsar.test.support.model.UserRecord

響應式支援

Spring Pulsar `2.0.0` 已移除響應式支援 - 不再發布 `spring-pulsar-reactive` 模組。

1.2 版本自 1.1 版本以來的新功能

本節涵蓋從 1.1 版本到 1.2 版本的更改。

自定義物件對映器

您可以提供自己的 Jackson `ObjectMapper`,Pulsar 將在生成和消費 JSON 訊息時使用它。有關更多詳細資訊,請參見 自定義物件對映器

預設租戶和名稱空間

您可以指定預設租戶和/或名稱空間,以便在針對非完全限定主題 URL 生產或消費訊息時使用。有關更多詳細資訊,請參見 預設租戶/名稱空間

訊息容器啟動策略

您現在可以將訊息監聽器容器啟動失敗策略配置為 `stop`、`continue` 或 `retry`。有關更多詳細資訊,請參閱受支援容器的相應部分 @PulsarListener@PulsarReader

訊息容器工廠定製器 (Spring Boot)

Spring Boot 引入了一個通用的訊息容器工廠定製器 `org.springframework.boot.pulsar.autoconfigure.PulsarContainerFactoryCustomizer>`,可用於進一步配置一個或多個支援以下監聽器註解的自動配置容器工廠:

  • 對於 `PulsarListener`,註冊一個或多個 PulsarContainerFactoryCustomizer> bean。

  • 對於 `@PulsarReader`,註冊一個或多個 PulsarContainerFactoryCustomizer> bean。

棄用

PulsarClient#getPartitionsForTopic(java.lang.String)

Pulsar 客戶端的 `3.3.1` 版本已棄用 `getPartitionsForTopic(java.lang.String)`,轉而使用 `getPartitionsForTopic(java.lang.String, boolean metadataAutoCreationEnabled)`。

PulsarTopic#builder

在使用 Spring Boot 時,`PulsarTopicBuilder` 現在是一個已註冊的 bean,其配置了域、租戶和名稱空間的預設值。因此,如果您使用 Spring Boot,您只需在需要時注入構建器即可。否則,直接使用 `PulsarTopicBuilder` 的其中一個建構函式。

監聽器/閱讀器容器工廠

引入了 `PulsarContainerFactory` 通用介面,以彌合監聽器和閱讀器容器工廠之間的差距。作為其中的一部分,以下 API 被棄用、複製並重命名:

  • `ListenerContainerFactory#createListenerContainer` 被 `ListenerContainerFactory#createRegisteredContainer` 替換。

  • `ReaderContainerFactory#createReaderContainer(E endpoint)` 被 `ReaderContainerFactory#createRegisteredContainer` 替換。

  • `ReaderContainerFactory#createReaderContainer(String…​ topics)` 被 `ReaderContainerFactory#createContainer` 替換。

ConcurrentPulsarListenerContainerFactoryCustomizer

`ConcurrentPulsarListenerContainerFactoryCustomizer` 的目的是定製 Spring Boot 自動配置的訊息容器工廠。然而,Spring Boot 引入了一個通用的訊息容器工廠定製器 `org.springframework.boot.pulsar.autoconfigure.PulsarContainerFactoryCustomizer>`,這使得不再需要此定製器。

將 `ConcurrentPulsarListenerContainerFactoryCustomizer` 的所有例項替換為 `org.springframework.boot.pulsar.autoconfigure.PulsarContainerFactoryCustomizer>`。

移除

以下先前已棄用的監聽器端點介面卡已被移除,取而代之的是監聽器端點介面中的預設方法:

  • org.springframework.pulsar.config.PulsarListenerEndpointAdapter

  • org.springframework.pulsar.reactive.config.ReactivePulsarListenerEndpointAdapter

破壞性變更

PulsarTopic#<init>

`PulsarTopic` 建構函式現在需要一個完全限定的主題名稱 (`domain://tenant/namespace/name`)。如果您正在呼叫建構函式,您需要確保傳入的主題是完全限定的。一個更好的替代方法是使用 `PulsarTopicBuilder`,因為它不需要完全限定的名稱,並且會為指定名稱中缺失的元件新增預設值。

PulsarReaderFactory#createReader

`PulsarReaderFactory#createReader` API 現在丟擲未檢查的 `PulsarException`,而不是已檢查的 `PulsarClientException`。請相應地替換此 API 上的任何 `try/catch` 塊。

1.1 版本自 1.0 版本以來的新功能

本節涵蓋從 1.0 版本到 1.1 版本的更改。

自動Schema支援

如果無法提前知道 Pulsar 主題的模式,您可以使用 AUTO Schemas 從代理生產/消費通用記錄。有關更多詳細資訊,請參閱 使用 AUTO_SCHEMA 生產使用 AUTO_SCHEMA 消費

儘管上述連結主要關注 `PulsarTemplate` 和 `@PulsarListener`,但此功能也支援 `ReactivePulsarTemplate`、`@ReactivePulsarListener` 和 `@PulsarReader`。每個的詳細資訊可在本參考指南的相應部分中找到。

透過訊息註解設定預設主題/模式

您現在可以使用 `@PulsarMessage` 標記訊息類,以指定在生產/消費該型別訊息時使用的 預設主題 和/或 預設模式

移除受檢異常

框架提供的 API 不再丟擲受檢的 `PulsarClientException`,而是丟擲非受檢的 `PulsarException`。

如果您之前捕獲或重新丟擲 `PulsarClientException` 只是為了迎合編譯器而實際上並未處理異常,則可以簡單地刪除您的 `catch` 或 `throws` 子句。如果您確實處理了異常,則需要在 `catch` 子句中將 `PulsarClientException` 替換為 `PulsarException`。

測試支援

`spring-pulsar-test` 模組現已可用,可幫助測試您的 Spring for Apache Pulsar 應用程式。有關更多詳細資訊,請參見 測試應用程式

© . This site is unofficial and not affiliated with VMware.