Managing persistent topics
Persistent helps to access topic which is a logical endpoint for publishing and consuming messages. Producers publish messages to the topic and consumers subscribe to the topic, to consume messages published to the topic.
In all of the instructions and commands below, the topic name structure is:
persistent://tenant/namespace/topic
Persistent topics resources
List of topics
It provides a list of persistent topics exist under a given namespace.
pulsar-admin
List of topics can be fetched using list
command.
$ pulsar-admin topics list \
my-tenant/my-namespace
REST API
GET /admin/v2/:schema/:tenant/:namespace/getList
Java
String namespace = "my-tenant/my-namespace";
admin.persistentTopics().getList(namespace);
Grant permission
It grants permissions on a client role to perform specific actions on a given topic.
pulsar-admin
Permission can be granted using grant-permission
command.
$ pulsar-admin topics grant-permission \
--actions produce,consume --role application1 \
persistent://test-tenant/ns1/tp1 \
REST API
POST /admin/v2/:schema/:tenant/:namespace/:topic/permissions/:role/grantPermissionsOnTopic
Java
String topic = "persistent://my-tenant/my-namespace/my-topic";
String role = "test-role";
Set<AuthAction> actions = Sets.newHashSet(AuthAction.produce, AuthAction.consume);
admin.persistentTopics().grantPermission(topic, role, actions);
Get permission
Permission can be fetched using permissions
command.
pulsar-admin
$ pulsar-admin topics permissions \
persistent://test-tenant/ns1/tp1 \
{
"application1": [
"consume",
"produce"
]
}
REST API
GET /admin/v2/:schema/:tenant/:namespace/:topic/permissions/getPermissionsOnTopic
Java
String topic = "persistent://my-tenant/my-namespace/my-topic";
admin.persistentTopics().getPermissions(topic);
Revoke permission
It revokes a permission which was granted on a client role.
pulsar-admin
Permission can be revoked using revoke-permission
command.
$ pulsar-admin topics revoke-permission \
--role application1 \
persistent://test-tenant/ns1/tp1 \
{
"application1": [
"consume",
"produce"
]
}
REST API
DELETE /admin/v2/:schema/:tenant/:namespace/:topic/permissions/:role/revokePermissionsOnTopic
Java
String topic = "persistent://my-tenant/my-namespace/my-topic";
String role = "test-role";
admin.persistentTopics().revokePermissions(topic, role);
Delete topic
It deletes a topic. The topic cannot be deleted if there's any active subscription or producers connected to it.
pulsar-admin
Topic can be deleted using delete
command.
$ pulsar-admin topics delete \
persistent://test-tenant/ns1/tp1 \
REST API
DELETE /admin/v2/:schema/:tenant/:namespace/:topic/deleteTopic
Java
String topic = "persistent://my-tenant/my-namespace/my-topic";
admin.persistentTopics().delete(topic);