有何新特性?
1.2 版本與 1.1 版本相比有何新特性
本節介紹從 1.1 版本到 1.2 版本所做的更改。
自定義 Object Mapper
您可以提供自己的 Jackson ObjectMapper
,Pulsar 在生產和消費 JSON 訊息時將使用它。有關更多詳細資訊,請參閱自定義 Object Mapper。
預設租戶和名稱空間
在對非完全限定的主題 URL 進行生產或消費訊息時,您可以指定要使用的預設租戶和/或名稱空間。有關更多詳細資訊,請參閱預設租戶 / 名稱空間。
訊息容器啟動策略
您現在可以將訊息監聽器容器啟動失敗策略配置為 stop
(停止)、continue
(繼續)或 retry
(重試)。有關更多詳細資訊,請參閱其中一個受支援容器的相應章節:@PulsarListener、@PulsarReader 或 @ReactivePulsarListener
訊息容器工廠定製器 (Spring Boot)
Spring Boot 引入了一個通用的訊息容器工廠定製器 org.springframework.boot.autoconfigure.pulsar.PulsarContainerFactoryCustomizer<T extends PulsarContainerFactory<?, ?>>
,可用於進一步配置支援以下監聽器註解的一個或多個自動配置的容器工廠
-
對於
@PulsarListener
,註冊一個或多個PulsarContainerFactoryCustomizer<ConcurrentPulsarListenerContainerFactory<?>>
bean。 -
對於
@PulsarReader
,註冊一個或多個PulsarContainerFactoryCustomizer<DefaultPulsarReaderContainerFactory<?>>
bean。 -
對於
@ReactivePulsarListener
,註冊一個或多個PulsarContainerFactoryCustomizer<DefaultReactivePulsarListenerContainerFactory<?>>
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,配置了 domain、tenant 和 namespace 的預設值。因此,如果您使用 Spring Boot,只需在需要的地方注入該 builder 即可。否則,請直接使用 PulsarTopicBuilder
的某個建構函式。
Listener/ReaderContainerFactory
引入了 PulsarContainerFactory
公共介面,以彌合 listener 和 reader 容器工廠之間的差距。作為這項工作的一部分,以下 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.autoconfigure.pulsar.PulsarContainerFactoryCustomizer<T extends PulsarContainerFactory<?, ?>>
,這使得不再需要此定製器。
將所有 ConcurrentPulsarListenerContainerFactoryCustomizer
的例項替換為 org.springframework.boot.autoconfigure.pulsar.PulsarContainerFactoryCustomizer<ConcurrentPulsarListenerContainerFactoryCustomizer<?>>
。
移除
以下先前已棄用的監聽器端點介面卡已被移除,轉而使用監聽器端點介面中的預設方法:
-
org.springframework.pulsar.config.PulsarListenerEndpointAdapter
-
org.springframework.pulsar.reactive.config.ReactivePulsarListenerEndpointAdapter
1.1 版本與 1.0 版本相比有何新特性
本節介紹從 1.0 版本到 1.1 版本所做的更改。
Auto Schema 支援
如果無法提前知道 Pulsar 主題的 schema,您可以使用 AUTO Schemas 來生產/消費泛型記錄。有關更多詳細資訊,請參閱使用 AUTO_SCHEMA 生產和使用 AUTO_SCHEMA 消費。
雖然上述連結側重於 PulsarTemplate 和 @PulsarListener ,但此功能也支援 ReactivePulsarTemplate 、@ReactivePulsarListener 和 @PulsarReader 。每項功能的詳細資訊可在本參考指南的相應章節中找到。 |
移除 checked 異常
框架提供的 API 不再丟擲 checked 的 PulsarClientException
,而是 unchecked 的 PulsarException
。
如果您之前捕獲或重新丟擲 PulsarClientException 只是為了滿足編譯器要求而並未實際處理異常,您可以直接移除 catch 或 throws 子句。如果您確實處理了異常,則需要在您的 catch 子句中將 PulsarClientException 替換為 PulsarException 。 |
測試支援
spring-pulsar-test
模組現已可用,以幫助測試您的 Spring for Apache Pulsar 應用程式。有關更多詳細資訊,請參閱測試應用程式。