跳到主要内容
版本:2.0.7

默认租户/命名空间

Doubao 中英对照 Default Tenant / Namespace

Pulsar 内置了对多租户的支持。在 Pulsar 中生产或消费消息时,指定的 topic 实际上是一个如下格式的 topic URL:

(persistent|non-persistent)://tenant/namespace/topic

该 URL 决定了操作所针对的租户和命名空间。然而,当未完全限定时(即只指定了 topic 名称),会使用默认租户 public 和默认命名空间 default。

Spring for Apache Pulsar 允许你指定默认租户和/或命名空间,以便在针对非完全限定的 topic URL 生产或消费消息时使用。

配置 {#_configuration}### 使用 Spring Boot​

使用 Spring Boot 时,你只需设置 spring.pulsar.defaults.topic.tenant 和 spring.pulsar.defaults.topic.namespace 应用属性即可指定这些默认值。

如果你想禁用此特性,只需将 spring.pulsar.defaults.topic.enabled 属性设置为 false。

不使用 Spring Boot​

然而,如果你改为手动配置组件,则在构造相应的生产者或消费者工厂时,需要提供一个配置了所需默认 topic 和命名空间的 PulsarTopicBuilder。所有默认的 consumer/reader/producer 工厂实现都允许指定 topic builder。

备注

你需要在每个希望使用默认租户/命名空间的手动配置工厂上指定 topic builder。