Pulsar 管理
1. Pulsar Admin 客户端
在 Pulsar 管理端,Spring Boot 自动配置提供了一个PulsarAdministration
来管理 Pulsar 集群。
管理实现一个名为PulsarAdminOperations
并提供一个createOrModify
方法通过其 Contract 处理 topic 管理。
当您使用 Pulsar Spring Boot Starters时,您将获得PulsarAdministration
auto-configured的。
默认情况下,应用程序会尝试连接到位于http://localhost:8080
.
这可以通过设置spring.pulsar.admin.service-url
property 设置为表单中的其他值(http|https)://<host>:<port>
.
有许多应用程序属性可用于配置客户端。
请参阅spring.pulsar.admin.*
应用程序属性。
2. 自动创建主题
初始化时,PulsarAdministration
检查是否有任何PulsarTopic
bean 中的对象。
对于所有这些 bean,PulsarAdministration
创建相应的主题,或者在必要时修改分区的数量。
以下示例显示了如何添加PulsarTopic
bean 让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();
}