脉冲星管理
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(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 时, |