最新动态?
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
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
1.1 版本自 1.0 版本以来的新功能
本节涵盖从 1.0 版本到 1.1 版本的更改。
自动Schema支持
如果无法提前知道 Pulsar 主题的模式,您可以使用 AUTO Schemas 从代理生产/消费通用记录。有关更多详细信息,请参阅 使用 AUTO_SCHEMA 生产 和 使用 AUTO_SCHEMA 消费。
| 尽管上述链接主要关注 `PulsarTemplate` 和 `@PulsarListener`,但此功能也支持 `ReactivePulsarTemplate`、`@ReactivePulsarListener` 和 `@PulsarReader`。每个的详细信息可在本参考指南的相应部分中找到。 |
移除受检异常
框架提供的 API 不再抛出受检的 `PulsarClientException`,而是抛出非受检的 `PulsarException`。
| 如果您之前捕获或重新抛出 `PulsarClientException` 只是为了迎合编译器而实际上并未处理异常,则可以简单地删除您的 `catch` 或 `throws` 子句。如果您确实处理了异常,则需要在 `catch` 子句中将 `PulsarClientException` 替换为 `PulsarException`。 |
测试支持
`spring-pulsar-test` 模块现已可用,可帮助测试您的 Spring for Apache Pulsar 应用程序。有关更多详细信息,请参见 测试应用程序。