Managing Namespaces
Pulsar namespaces are logical groupings of topics.
Namespaces can be managed via:
- The
namespacescommand of thepulsar-admintool - The
/admin/v2/namespacesendpoint of the admin REST API - The
namespacesmethod of the PulsarAdmin object in the Java API
Namespaces resources
Create namespaces
You can create new namespaces under a given tenant.
- pulsar-admin
- REST API
- Java
Use the create subcommand and specify the namespace by name:
$ pulsar-admin namespaces create test-tenant/test-namespace
admin.namespaces().createNamespace(namespace);
Get policies
You can fetch the current policies associated with a namespace at any time.
- pulsar-admin
- REST API
- Java
Use the policies subcommand and specify the namespace:
$ pulsar-admin namespaces policies test-tenant/test-namespace
{
"auth_policies": {
"namespace_auth": {},
"destination_auth": {}
},
"replication_clusters": [],
"bundles_activated": true,
"bundles": {
"boundaries": [
"0x00000000",
"0xffffffff"
],
"numBundles": 1
},
"backlog_quota_map": {},
"persistence": null,
"latency_stats_sample_rate": {},
"message_ttl_in_seconds": 0,
"retention_policies": null,
"deleted": false
}
admin.namespaces().getPolicies(namespace);
List namespaces
You can list all namespaces within a given Pulsar tenant.
- pulsar-admin
- REST API
- Java
Use the list subcommand and specify the tenant:
$ pulsar-admin namespaces list test-tenant
test-tenant/ns1
test-tenant/ns2
admin.namespaces().getNamespaces(tenant);
Delete namespaces
You can delete existing namespaces from a tenant.
- pulsar-admin
- REST API
- Java
Use the delete subcommand and specify the namespace:
$ pulsar-admin namespaces delete test-tenant/ns1
admin.namespaces().deleteNamespace(namespace);
Configure replication clusters
Set replication cluster
It sets replication clusters for a namespace, so Pulsar can internally replicate publish message from one colo to another colo.
- pulsar-admin
- REST API
- Java
$ pulsar-admin namespaces set-clusters test-tenant/ns1 \
--clusters cl1
admin.namespaces().setNamespaceReplicationClusters(namespace, clusters);
Get replication cluster
It gives a list of replication clusters for a given namespace.
- pulsar-admin
- REST API
- Java
$ pulsar-admin namespaces get-clusters test-tenant/cl1/ns1
cl2
admin.namespaces().getNamespaceReplicationClusters(namespace)
Configure backlog quota policies
Set backlog quota policies
Backlog quota helps the broker to restrict bandwidth/storage of a namespace once it reaches a certain threshold limit. Admin can set the limit and take corresponding action after the limit is reached.
-
producer_request_hold: broker will hold and not persist produce request payload
-
producer_exception: broker disconnects with the client by giving an exception.
-
consumer_backlog_eviction: broker will start discarding backlog messages
Backlog quota restriction can be taken care by defining restriction of backlog-quota-type: destination_storage
- pulsar-admin
- REST API
- Java
$ pulsar-admin namespaces set-backlog-quota --limit 10 --policy producer_request_hold test-tenant/ns1
N/A
admin.namespaces().setBacklogQuota(namespace, new BacklogQuota(limit, policy))
Get backlog quota policies
It shows a configured backlog quota for a given namespace.
- pulsar-admin
- REST API
- Java
$ pulsar-admin namespaces get-backlog-quotas test-tenant/ns1
{
"destination_storage": {
"limit": 10,
"policy": "producer_request_hold"
}
}
admin.namespaces().getBacklogQuotaMap(namespace);
Remove backlog quota policies
It removes backlog quota policies for a given namespace
- pulsar-admin
- REST API
- Java
$ pulsar-admin namespaces remove-backlog-quota test-tenant/ns1
N/A
admin.namespaces().removeBacklogQuota(namespace, backlogQuotaType)
Configure persistence policies
Set persistence policies
Persistence policies allow to configure persistency-level for all topic messages under a given namespace.
-
Bookkeeper-ack-quorum: Number of acks (guaranteed copies) to wait for each entry, default: 0
-
Bookkeeper-ensemble: Number of bookies to use for a topic, default: 0
-
Bookkeeper-write-quorum: How many writes to make of each entry, default: 0
-
Ml-mark-delete-max-rate: Throttling rate of mark-delete operation (0 means no throttle), default: 0.0
- pulsar-admin
- REST API
- Java
$ pulsar-admin namespaces set-persistence --bookkeeper-ack-quorum 2 --bookkeeper-ensemble 3 --bookkeeper-write-quorum 2 --ml-mark-delete-max-rate 0 test-tenant/ns1
N/A
admin.namespaces().setPersistence(namespace,new PersistencePolicies(bookkeeperEnsemble, bookkeeperWriteQuorum,bookkeeperAckQuorum,managedLedgerMaxMarkDeleteRate))
Get persistence policies
It shows the configured persistence policies of a given namespace.
- pulsar-admin
- REST API
- Java
$ pulsar-admin namespaces get-persistence test-tenant/ns1
{
"bookkeeperEnsemble": 3,
"bookkeeperWriteQuorum": 2,
"bookkeeperAckQuorum": 2,
"managedLedgerMaxMarkDeleteRate": 0
}
admin.namespaces().getPersistence(namespace)
Configure namespace bundles
Unload namespace bundles
The namespace bundle is a virtual group of topics which belong to the same namespace. If the broker gets overloaded with the number of bundles, this command can help unload a bundle from that broker, so it can be served by some other less-loaded brokers. The namespace bundle ID ranges from 0x00000000 to 0xffffffff.
- pulsar-admin
- REST API
- Java
$ pulsar-admin namespaces unload --bundle 0x00000000_0xffffffff test-tenant/ns1
N/A
admin.namespaces().unloadNamespaceBundle(namespace, bundle)
Split namespace bundles
Each namespace bundle can contain multiple topics and each bundle can be served by only one broker. If a single bundle is creating an excessive load on a broker, an admin splits the bundle using this command permitting one or more of the new bundles to be unloaded thus spreading the load across the brokers.
- pulsar-admin
- REST API
- Java
$ pulsar-admin namespaces split-bundle --bundle 0x00000000_0xffffffff test-tenant/ns1
N/A
admin.namespaces().splitNamespaceBundle(namespace, bundle, unloadSplitBundles, splitAlgorithmName)