Managing Namespaces

Pulsar namespaces are logical groupings of topics.

Namespaces can be managed via:

Namespaces resources

Create

You can create new namespaces under a given tenant.

pulsar-admin

Use the create subcommand and specify the namespace by name:

  1. $ pulsar-admin namespaces create test-tenant/test-namespace

REST API

PUT/admin/v2/namespaces/:tenant/:namespace

Java

  1. admin.namespaces().createNamespace(namespace);

Get policies

You can fetch the current policies associated with a namespace at any time.

pulsar-admin

Use the policies subcommand and specify the namespace:

  1. $ pulsar-admin namespaces policies test-tenant/test-namespace
  2. {
  3. "auth_policies": {
  4. "namespace_auth": {},
  5. "destination_auth": {}
  6. },
  7. "replication_clusters": [],
  8. "bundles_activated": true,
  9. "bundles": {
  10. "boundaries": [
  11. "0x00000000",
  12. "0xffffffff"
  13. ],
  14. "numBundles": 1
  15. },
  16. "backlog_quota_map": {},
  17. "persistence": null,
  18. "latency_stats_sample_rate": {},
  19. "message_ttl_in_seconds": 0,
  20. "retention_policies": null,
  21. "deleted": false
  22. }

REST API

GET/admin/v2/namespaces/:tenant/:namespace

Java

  1. admin.namespaces().getPolicies(namespace);

List namespaces within a tenant

You can list all namespaces within a given Pulsar tenant.

pulsar-admin

Use the list subcommand and specify the tenant:

  1. $ pulsar-admin namespaces list test-tenant
  2. test-tenant/ns1
  3. test-tenant/ns2

REST API

GET/admin/v2/namespaces/:tenant

Java

  1. admin.namespaces().getNamespaces(tenant);

Delete

You can delete existing namespaces from a tenant.

pulsar-admin

Use the delete subcommand and specify the namespace:

  1. $ pulsar-admin namespaces delete test-tenant/ns1

REST

DELETE/admin/v2/namespaces/:tenant/:namespace

Java

  1. admin.namespaces().deleteNamespace(namespace);

set replication cluster

It sets replication clusters for a namespace, so Pulsar can internally replicate publish message from one colo to another colo.

CLI
  1. $ pulsar-admin namespaces set-clusters test-tenant/ns1 \
  2. --clusters cl1
REST
  1. {@inject: endpoint|POST|/admin/v2/namespaces/:tenant/:namespace/replication|operation/setNamespaceReplicationClusters}
Java
  1. admin.namespaces().setNamespaceReplicationClusters(namespace, clusters);

get replication cluster

It gives a list of replication clusters for a given namespace.

CLI
  1. $ pulsar-admin namespaces get-clusters test-tenant/cl1/ns1
  1. cl2
REST
  1. {@inject: endpoint|GET|/admin/v2/namespaces/{tenant}/{namespace}/replication|operation/getNamespaceReplicationClusters}
Java
  1. admin.namespaces().getNamespaceReplicationClusters(namespace)

set backlog quota policies

Backlog quota helps broker to restrict bandwidth/storage of a namespace once it reach certain threshold limit . Admin can set this limit and one of the following action after the limit is reached.

  • producer_request_hold: broker will hold and not persist produce request payload

  • producer_exception: broker will disconnects with client by giving 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

CLI
  1. $ pulsar-admin namespaces set-backlog-quota --limit 10 --policy producer_request_hold test-tenant/ns1
  1. N/A
REST
  1. {@inject: endpoint|POST|/admin/v2/namespaces/{tenant}/{namespace}/backlogQuota|operation/setBacklogQuota}
Java
  1. admin.namespaces().setBacklogQuota(namespace, new BacklogQuota(limit, policy))

get backlog quota policies

It shows a configured backlog quota for a given namespace.

CLI
  1. $ pulsar-admin namespaces get-backlog-quotas test-tenant/ns1
  1. {
  2. "destination_storage": {
  3. "limit": 10,
  4. "policy": "producer_request_hold"
  5. }
  6. }
REST
  1. {@inject: endpoint|GET|/admin/v2/namespaces/{tenant}/{namespace}/backlogQuotaMap|operation/getBacklogQuotaMap}
Java
  1. admin.namespaces().getBacklogQuotaMap(namespace);

remove backlog quota policies

It removes backlog quota policies for a given namespace

CLI
  1. $ pulsar-admin namespaces remove-backlog-quota test-tenant/ns1
  1. N/A
REST
  1. {@inject: endpoint|DELETE|/admin/v2/namespaces/{tenant}/{namespace}/backlogQuota|operation/removeBacklogQuota}
Java
  1. admin.namespaces().removeBacklogQuota(namespace, backlogQuotaType)

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

CLI
  1. $ 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
  1. N/A
REST
  1. {@inject: endpoint|POST|/admin/v2/namespaces/{tenant}/{namespace}/persistence|operation/setPersistence}
Java
  1. admin.namespaces().setPersistence(namespace,new PersistencePolicies(bookkeeperEnsemble, bookkeeperWriteQuorum,bookkeeperAckQuorum,managedLedgerMaxMarkDeleteRate))

get persistence policies

It shows configured persistence policies of a given namespace.

CLI
  1. $ pulsar-admin namespaces get-persistence test-tenant/ns1
  1. {
  2. "bookkeeperEnsemble": 3,
  3. "bookkeeperWriteQuorum": 2,
  4. "bookkeeperAckQuorum": 2,
  5. "managedLedgerMaxMarkDeleteRate": 0
  6. }
REST
  1. {@inject: endpoint|GET|/admin/v2/namespaces/{tenant}/{namespace}/persistence|operation/getPersistence}
Java
  1. admin.namespaces().getPersistence(namespace)

unload namespace bundle

Namespace bundle is a virtual group of topics which belong to same namespace. If broker gets overloaded with number of bundles then this command can help to unload heavy bundle from that broker, so it can be served by some other less loaded broker. Namespace bundle is defined with it’s start and end range such as 0x00000000 and 0xffffffff.

CLI
  1. $ pulsar-admin namespaces unload --bundle 0x00000000_0xffffffff test-tenant/ns1
  1. N/A
REST
  1. {@inject: endpoint|PUT|/admin/v2/namespaces/{tenant}/{namespace}/{bundle}/unload|operation/unloadNamespaceBundle}
Java
  1. admin.namespaces().unloadNamespaceBundle(namespace, bundle)

set message-ttl

It configures message’s time to live (in seconds) duration.

CLI
  1. $ pulsar-admin namespaces set-message-ttl --messageTTL 100 test-tenant/ns1
  1. N/A
REST
  1. {@inject: endpoint|POST|/admin/v2/namespaces/{tenant}/{namespace}/messageTTL|operation/setNamespaceMessageTTL}
Java
  1. admin.namespaces().setNamespaceMessageTTL(namespace, messageTTL)

get message-ttl

It gives a message ttl of configured namespace.

CLI
  1. $ pulsar-admin namespaces get-message-ttl test-tenant/ns1
  1. 100
REST
  1. {@inject: endpoint|GET|/admin/v2/namespaces/{tenant}/{namespace}/messageTTL|operation/getNamespaceMessageTTL}
Java
  1. admin.namespaces().getNamespaceMessageTTL(namespace)

split bundle

Each namespace bundle can contain multiple topics and each bundle can be served by only one broker. If bundle gets heavy with multiple live topics in it then it creates load on that broker and in order to resolve this issue, admin can split bundle using this command.

CLI
  1. $ pulsar-admin namespaces split-bundle --bundle 0x00000000_0xffffffff test-tenant/ns1
  1. N/A
REST
  1. {@inject: endpoint|PUT|/admin/v2/namespaces/{tenant}/{namespace}/{bundle}/split|operation/splitNamespaceBundle}
Java
  1. admin.namespaces().splitNamespaceBundle(namespace, bundle)

clear backlog

It clears all message backlog for all the topics those belong to specific namespace. You can also clear backlog for a specific subscription as well.

CLI
  1. $ pulsar-admin namespaces clear-backlog --sub my-subscription test-tenant/ns1
  1. N/A
REST
  1. {@inject: endpoint|POST|/admin/v2/namespaces/{tenant}/{namespace}/clearBacklog|operation/clearNamespaceBacklogForSubscription}
Java
  1. admin.namespaces().clearNamespaceBacklogForSubscription(namespace, subscription)

clear bundle backlog

It clears all message backlog for all the topics those belong to specific NamespaceBundle. You can also clear backlog for a specific subscription as well.

CLI
  1. $ pulsar-admin namespaces clear-backlog --bundle 0x00000000_0xffffffff --sub my-subscription test-tenant/ns1
  1. N/A
REST
  1. {@inject: endpoint|POST|/admin/v2/namespaces/{tenant}/{namespace}/{bundle}/clearBacklog|operation/clearNamespaceBundleBacklogForSubscription}
Java
  1. admin.namespaces().clearNamespaceBundleBacklogForSubscription(namespace, bundle, subscription)

set retention

Each namespace contains multiple topics and each topic’s retention size (storage size) should not exceed to a specific threshold or it should be stored till certain time duration. This command helps to configure retention size and time of topics in a given namespace.

CLI
  1. $ pulsar-admin set-retention --size 10 --time 100 test-tenant/ns1
  1. N/A
REST
  1. {@inject: endpoint|POST|/admin/v2/namespaces/{tenant}/{namespace}/retention|operation/setRetention}
Java
  1. admin.namespaces().setRetention(namespace, new RetentionPolicies(retentionTimeInMin, retentionSizeInMB))

get retention

It shows retention information of a given namespace.

CLI
  1. $ pulsar-admin namespaces get-retention test-tenant/ns1
  1. {
  2. "retentionTimeInMinutes": 10,
  3. "retentionSizeInMB": 100
  4. }
REST
  1. {@inject: endpoint|GET|/admin/v2/namespaces/{tenant}/{namespace}/retention|operation/getRetention}
Java
  1. admin.namespaces().getRetention(namespace)

set dispatch throttling

It sets message dispatch rate for all the topics under a given namespace.Dispatch rate can be restricted by number of message per X seconds (msg-dispatch-rate) or by number of message-bytes per X second (byte-dispatch-rate).dispatch rate is in second and it can be configured with dispatch-rate-period. Default value of msg-dispatch-rate and byte-dispatch-rate is -1 whichdisables the throttling.

CLI
  1. $ pulsar-admin namespaces set-dispatch-rate test-tenant/ns1 \
  2. --msg-dispatch-rate 1000 \
  3. --byte-dispatch-rate 1048576 \
  4. --dispatch-rate-period 1
REST
  1. {@inject: endpoint|POST|/admin/v2/namespaces/{tenant}/{namespace}/dispatchRate|operation/setDispatchRate}
Java
  1. admin.namespaces().setDispatchRate(namespace, new DispatchRate(1000, 1048576, 1))

get configured message-rate

It shows configured message-rate for the namespace (topics under this namespace can dispatch this many messages per second)

CLI
  1. $ pulsar-admin namespaces get-dispatch-rate test-tenant/ns1
  1. {
  2. "dispatchThrottlingRatePerTopicInMsg" : 1000,
  3. "dispatchThrottlingRatePerTopicInByte" : 1048576,
  4. "ratePeriodInSecond" : 1
  5. }
REST
  1. {@inject: endpoint|GET|/admin/v2/namespaces/{tenant}/{namespace}/dispatchRate|operation/getDispatchRate}
Java
  1. admin.namespaces().getDispatchRate(namespace)

set dispatch throttling for subscription

It sets message dispatch rate for all the subscription of topics under a given namespace.Dispatch rate can be restricted by number of message per X seconds (msg-dispatch-rate) or by number of message-bytes per X second (byte-dispatch-rate).dispatch rate is in second and it can be configured with dispatch-rate-period. Default value of msg-dispatch-rate and byte-dispatch-rate is -1 whichdisables the throttling.

CLI
  1. $ pulsar-admin namespaces set-subscription-dispatch-rate test-tenant/ns1 \
  2. --msg-dispatch-rate 1000 \
  3. --byte-dispatch-rate 1048576 \
  4. --dispatch-rate-period 1
REST
  1. {@inject: endpoint|POST|/admin/v2/namespaces/{tenant}/{namespace}/subscriptionDispatchRate|operation/setDispatchRate}
Java
  1. admin.namespaces().setSubscriptionDispatchRate(namespace, new DispatchRate(1000, 1048576, 1))

get configured message-rate

It shows configured message-rate for the namespace (topics under this namespace can dispatch this many messages per second)

CLI
  1. $ pulsar-admin namespaces get-subscription-dispatch-rate test-tenant/ns1
  1. {
  2. "dispatchThrottlingRatePerTopicInMsg" : 1000,
  3. "dispatchThrottlingRatePerTopicInByte" : 1048576,
  4. "ratePeriodInSecond" : 1
  5. }
REST
  1. {@inject: endpoint|GET|/admin/v2/namespaces/{tenant}/{namespace}/subscriptionDispatchRate|operation/getDispatchRate}
Java
  1. admin.namespaces().getSubscriptionDispatchRate(namespace)

set dispatch throttling for subscription

It sets message dispatch rate for all the replicator between replication clusters under a given namespace.Dispatch rate can be restricted by number of message per X seconds (msg-dispatch-rate) or by number of message-bytes per X second (byte-dispatch-rate).dispatch rate is in second and it can be configured with dispatch-rate-period. Default value of msg-dispatch-rate and byte-dispatch-rate is -1 whichdisables the throttling.

CLI
  1. $ pulsar-admin namespaces set-replicator-dispatch-rate test-tenant/ns1 \
  2. --msg-dispatch-rate 1000 \
  3. --byte-dispatch-rate 1048576 \
  4. --dispatch-rate-period 1
REST
  1. {@inject: endpoint|POST|/admin/v2/namespaces/{tenant}/{namespace}/replicatorDispatchRate|operation/setDispatchRate}
Java
  1. admin.namespaces().setReplicatorDispatchRate(namespace, new DispatchRate(1000, 1048576, 1))

get configured message-rate

It shows configured message-rate for the namespace (topics under this namespace can dispatch this many messages per second)

CLI
  1. $ pulsar-admin namespaces get-replicator-dispatch-rate test-tenant/ns1
  1. {
  2. "dispatchThrottlingRatePerTopicInMsg" : 1000,
  3. "dispatchThrottlingRatePerTopicInByte" : 1048576,
  4. "ratePeriodInSecond" : 1
  5. }
REST
  1. {@inject: endpoint|GET|/admin/v2/namespaces/{tenant}/{namespace}/replicatorDispatchRate|operation/getDispatchRate}
Java
  1. admin.namespaces().getReplicatorDispatchRate(namespace)

Namespace isolation

Coming soon.

Unloading from a broker

You can unload a namespace, or a namespace bundle, from the Pulsar broker that is currently responsible for it.

pulsar-admin

Use the unload subcommand of the namespaces command.

CLI
  1. $ pulsar-admin namespaces unload my-tenant/my-ns
REST
  1. {@inject: endpoint|PUT|/admin/v2/namespaces/{tenant}/{namespace}/unload|operation/unloadNamespace}
Java
  1. admin.namespaces().unload(namespace)