Pulsar Administration
1. Pulsar Admin Client
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 a createOrModify
method to handle topic administration through its contract.
When you use the Pulsar Spring Boot starter, you get the PulsarAdministration
auto-configured.
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>
.
There are many application properties available to configure the client.
See the spring.pulsar.admin.*
application properties.
1.1. Authentication
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
.
2. Automatic Topic Creation
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.
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();
}