什么是新内容?
自 1.2 以来 2.0 的新特性
本部分涵盖从1.2版本到2.0版本的更改内容。
Spring 重试替换为核心重试
近期,所有对 Spring Retry 的使用都已替换为由 Spring Framework 引入的更简单的重试机制。
这主要是一个在重启消息容器时使用的内部实现细节。
这只会影响你,如果你之前通过一个PulsarContainerFactoryCustomizer类型的bean提供了自定义的RetryTemplate。
The RetryTemplate 类仍然存在于 Core Retry 中,但包名从 org.springframework.retry.support 更改为 org.springframework.core.retry,并且 API 有轻微的变化。
查看 提交 了解更多详情。
移除
previously 废弃的 API
以下此前已弃用的API,在2.0.x版本中被标记为移除,现已被移除:
-
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
最新更新 in 1.2 自 1.1
本部分涵盖从1.1版本到1.2版本的更改内容。
自定义对象映射器
You can provide your own Jackson ObjectMapper that Pulsar will use when producing and consuming JSON messages.
See Custom Object Mapper for more details.
默认租户和命名空间
您可以在使用非完全限定的主题URL进行消息的生产和消费时,指定默认租户和/或命名空间。 查看 默认租户 / 命名空间 以获取更多详情。
消息容器启动策略
您现在可以将消息监听容器启动失败策略配置为 stop,continue 或 retry。
有关详细信息,请参阅对应的支持容器的相应部分 @PulsarListener 或 @PulsarReader。
消息容器工厂自定义器 (Spring Boot)
Spring Boot 引入了一个通用的消息容器工厂自定义器 org.springframework.boot.pulsar.autoconfigure.PulsarContainerFactoryCustomizer<T extends PulsarContainerFactory<?, ?>>,可以用于进一步配置一个或多个为以下监听器注解所支持的自动配置容器工厂:
-
为 0 注册一个或多个 PulsarContainerFactoryCustomizer<ConcurrentPulsarListenerContainerFactory<?>> beans。
-
为 0 注册一个或多个 PulsarContainerFactoryCustomizer<DefaultPulsarReaderContainerFactory<?>> beans。
弃用
PulsarClient#getPartitionsForTopic(java.lang.String)
版本 3.3.1 的 Pulsar 客户端弃用 getPartitionsForTopic(java.lang.String),改用 getPartitionsForTopic(java.lang.String, boolean metadataAutoCreationEnabled)。
Pulsar主题#构建器
当使用 Spring Boot 时,PulsarTopicBuilder 现在是一个已注册的 bean,其 domain、tenant 和 namespace 配置使用默认值。
因此,如果您使用 Spring Boot,可以在需要的地方直接注入 builder。
否则,请直接使用其中一个 PulsarTopicBuilder 构造函数。
监听器/读取器容器工厂
The 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<T extends PulsarContainerFactory<?, ?>>,从而不再需要此自定义器。
替换所有 ConcurrentPulsarListenerContainerFactoryCustomizer 实例为 org.springframework.boot.pulsar.autoconfigure.PulsarContainerFactoryCustomizer<ConcurrentPulsarListenerContainerFactoryCustomizer<?>>。
移除
以下此前已弃用的监听器端点适配器已移除,以便优先使用监听器端点接口中的默认方法:
-
org.springframework.pulsar.config.PulsarListenerEndpointAdapter -
org.springframework.pulsar.reactive.config.ReactivePulsarListenerEndpointAdapter
最新更新 in 1.1 自 1.0
本部分涵盖了从 1.0 版本到 1.1 版本的更改内容。
自动 Schema 支持
如果没有提前知道 Pulsar 主题的模式,您可以使用 AUTO Schemas 来向/从 brokers 生产/消费通用记录。 查看 使用 AUTO_SCHEMA 生产 和 使用 AUTO_SCHEMA 消费 以获取更多详情。
虽然上述链接重点介绍了 PulsarTemplate 和 @PulsarListener,但该功能也支持在 ReactivePulsarTemplate、@ReactivePulsarListener 和 @PulsarReader 中使用。每个版本的详细信息都可以在其参考指南的相应部分中找到。 |
移除受检异常
框架提供的API不再抛出受检的PulsarClientException,而是抛出不受检的PulsarException。
如果你之前只是捕获或重新抛出 PulsarClientException 来让编译器满意,但实际上并没有处理该异常,你可以简单地移除你的 catch 或 throws 子句。
如果你实际上是在处理该异常,你则需要在 catch 子句中将 PulsarClientException 替换为 PulsarException。 |
测试支持
The spring-pulsar-test 模块现已可用,以帮助您测试 Spring for Apache Pulsar 应用程序。
查看 测试应用程序 了解更多详情。