有何新特性?
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 应用程序。有关更多详细信息,请参阅测试应用程序。