脉冲星管理
1. Pulsar 管理客户端
在 Pulsar 管理端,Spring Boot 自动配置提供了一个PulsarAdministration
来管理 Pulsar 集群。
管理部门实现了一个名为PulsarAdminOperations
并提供一个createOrModify
方法通过其合同处理主题管理。
当您使用 Pulsar Spring Boot Starters时,您将获得PulsarAdministration
自动配置。
默认情况下,应用程序会尝试连接到本地 Pulsar 实例http://localhost:8080
.
这可以通过设置spring.pulsar.admin.service-url
属性设置为表单中的不同值(http|https)://<host>:<port>
.
有许多应用程序属性可用于配置客户端。
请参阅spring.pulsar.admin.*
应用程序属性。
2. 自动创建主题
初始化时,PulsarAdministration
检查是否有PulsarTopic
bean 的 bean。
对于所有这些 bean,该PulsarAdministration
创建相应的主题,或者在必要时修改分区数。
以下示例演示如何添加PulsarTopic
豆子让PulsarAdministration
自动为您创建主题:
@Bean
PulsarTopic simpleTopic {
// This will create a non-partitioned topic in the public/default namespace
return PulsarTopic.builder("simple-topic").build();
}
@Bean
PulsarTopic partitionedTopic {
// This will create a partitioned topic with 3 partitions in the provided tenant and namespace
return PulsarTopic.builder("persistent://my-tenant/my-namespace/partitioned-topic", 3).build();
}