Pulsar Administration
Pulsar Admin Client
在 Pulsar 管理方面,Spring Boot 自动配置提供了一个 `PulsarAdministration`用于管理 Pulsar 集群。该管理实现在称为 `PulsarAdminOperations`的接口,并提供 {javadocs}/org/springframework/pulsar/core/PulsarAdminOperations.html[一个 `createOrModify`方法] 通过其契约处理主题管理。
On the Pulsar administration side, Spring Boot auto-configuration provides a PulsarAdministration
to manage Pulsar clusters.
The administration implements an interface called PulsarAdminOperations
and provides {javadocs}/org/springframework/pulsar/core/PulsarAdminOperations.html[a createOrModify
method] to handle topic administration through its contract.
当你使用 Pulsar Spring Boot starter 时,你获得了自动配置的 PulsarAdministration
。
When you use the Pulsar Spring Boot starter, you get the PulsarAdministration
auto-configured.
默认情况下,应用程序尝试在 http://localhost:8080
连接到本地 Pulsar 实例。这可以通过将 spring.pulsar.admin.service-url
属性设置为形式为 (http|https)://<host>:<port>
的其他值来调整。
By default, the application tries to connect to a local Pulsar instance at http://localhost:8080
.
This can be adjusted by setting the spring.pulsar.admin.service-url
property to a different value in the form (http|https)://<host>:<port>
.
有许多应用程序属性可用于配置客户端。请参阅 {spring-boot-pulsar-config-props}[spring.pulsar.admin.*
] 应用程序属性。
There are many application properties available to configure the client.
See the {spring-boot-pulsar-config-props}[spring.pulsar.admin.*
] application properties.
Authentication
在访问需要身份验证的 Pulsar 集群时,管理员客户端需要与常规 Pulsar 客户端相同的安全配置。您可以使用上述 security configuration 替换 spring.pulsar.client
为 spring.pulsar.admin
。
When accessing a Pulsar cluster that requires authentication, the admin client requires the same security configuration as the regular Pulsar client.
You can use the aforementioned security configuration by replacing spring.pulsar.client
with spring.pulsar.admin
.
Automatic Topic Creation
在初始化时,PulsarAdministration
会检查应用程序上下文中是否有任何 PulsarTopic
bean。对于所有此类 bean,PulsarAdministration
将创建相应的主题或(在必要时)修改分区数。
On initialization, the PulsarAdministration
checks if there are any PulsarTopic
beans in the application context.
For all such beans, the PulsarAdministration
either creates the corresponding topic or, if necessary, modifies the number of partitions.
以下示例演示了如何添加 PulsarTopic
bean 以便让 PulsarAdministration
为你自动创建主题:
The following example shows how to add PulsarTopic
beans to let the PulsarAdministration
auto-create topics for you:
@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();
}