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(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 时, |