脉冲星管理

1. Pulsar 管理客户端

在 Pulsar 管理端,Spring Boot 自动配置提供了一个PulsarAdministration来管理 Pulsar 集群。 管理部门实现了一个名为PulsarAdminOperations并提供一个createOrModify方法通过其合同处理主题管理。spring-doc.cadn.net.cn

当您使用 Pulsar Spring Boot Starters时,您将获得PulsarAdministration自动配置。spring-doc.cadn.net.cn

默认情况下,应用程序会尝试连接到本地 Pulsar 实例http://localhost:8080. 这可以通过设置spring.pulsar.admin.service-url属性设置为表单中的不同值(http|https)://<host>:<port>.spring-doc.cadn.net.cn

有许多应用程序属性可用于配置客户端。 请参阅spring.pulsar.admin.*应用程序属性。spring-doc.cadn.net.cn

1.1. 身份验证

当访问需要身份验证的 Pulsar 集群时,管理客户端需要与常规 Pulsar 客户端相同的安全配置。 您可以通过将spring.pulsar.clientspring.pulsar.admin.spring-doc.cadn.net.cn

2. 自动创建主题

初始化时,PulsarAdministration检查是否有PulsarTopicbean 的 bean。 对于所有这些 bean,该PulsarAdministration创建相应的主题,或者在必要时修改分区数。spring-doc.cadn.net.cn

以下示例演示如何添加PulsarTopic豆子让PulsarAdministration自动为您创建主题:spring-doc.cadn.net.cn

@Bean
PulsarTopic simpleTopic(PulsarTopicBuilder topicBuilder) {
    // This will create a non-partitioned persistent topic in the 'public/default' tenant/namespace
    return topicBuilder.name("my-topic").build();
}

@Bean
PulsarTopic partitionedTopic(PulsarTopicBuilder topicBuilder) {
    // This will create a persistent topic with 3 partitions in the provided tenant and namespace
    return topicBuilder
        .name("persistent://my-tenant/my-namespace/partitioned-topic")
        .numberOfPartitions(3)
        .build();
}

使用 Spring Boot 时,PulsarTopicBuilder是一个已注册的 Bean,它配置了域、租户和命名空间的默认值。 您可以简单地在需要的地方注入构建器。 否则,请使用PulsarTopicBuilder构造函数直接。spring-doc.cadn.net.cn