Managing non-persistent topics

Non-persistent can be used in applications that only want to consume real time published messages anddo not need persistent guarantee that can also reduce message-publish latency by removing overhead ofpersisting messages.

In all of the instructions and commands below, the topic name structure is:

  1. non-persistent://tenant/namespace/topic

Non-persistent topics resources

Get stats

It shows current statistics of a given non-partitioned topic.

  • msgRateIn: The sum of all local and replication publishers' publish rates in messages per second

  • msgThroughputIn: Same as above, but in bytes per second instead of messages per second

  • msgRateOut: The sum of all local and replication consumers' dispatch rates in messages per second

  • msgThroughputOut: Same as above, but in bytes per second instead of messages per second

  • averageMsgSize: The average size in bytes of messages published within the last interval

  • publishers: The list of all local publishers into the topic. There can be zero or thousands

  • averageMsgSize: Average message size in bytes from this publisher within the last interval

  • producerId: Internal identifier for this producer on this topic

  • producerName: Internal identifier for this producer, generated by the client library

  • address: IP address and source port for the connection of this producer

  • connectedSince: Timestamp this producer was created or last reconnected

  • subscriptions: The list of all local subscriptions to the topic

  • my-subscription: The name of this subscription (client defined)

  • type: This subscription type

  • consumers: The list of connected consumers for this subscription

  • consumerName: Internal identifier for this consumer, generated by the client library

  • availablePermits: The number of messages this consumer has space for in the client library's listen queue. A value less than 1 means the client library's queue is full and receive() isn't being called. A non-negative value means this consumer is ready to be dispatched messages.

  • replication: This section gives the stats for cross-colo replication of this topic

  • connected: Whether the outbound replicator is connected

  • inboundConnection: The IP and port of the broker in the remote cluster's publisher connection to this broker

  • inboundConnectedSince: The TCP connection being used to publish messages to the remote cluster. If there are no local publishers connected, this connection is automatically closed after a minute.

  • msgDropRate: for publisher: publish: broker only allows configured number of in flight per connection, and drops all other published messages above the threshold. Broker also drops messages for subscriptions in case of unavailable limit and connection is not writable.

  1. {
  2. "msgRateIn": 4641.528542257553,
  3. "msgThroughputIn": 44663039.74947473,
  4. "msgRateOut": 0,
  5. "msgThroughputOut": 0,
  6. "averageMsgSize": 1232439.816728665,
  7. "storageSize": 135532389160,
  8. "msgDropRate" : 0.0,
  9. "publishers": [
  10. {
  11. "msgRateIn": 57.855383881403576,
  12. "msgThroughputIn": 558994.7078932219,
  13. "averageMsgSize": 613135,
  14. "producerId": 0,
  15. "producerName": null,
  16. "address": null,
  17. "connectedSince": null,
  18. "msgDropRate" : 0.0
  19. }
  20. ],
  21. "subscriptions": {
  22. "my-topic_subscription": {
  23. "msgRateOut": 0,
  24. "msgThroughputOut": 0,
  25. "msgBacklog": 116632,
  26. "type": null,
  27. "msgRateExpired": 36.98245516804671,
  28. "consumers" : [ {
  29. "msgRateOut" : 20343.506296021893,
  30. "msgThroughputOut" : 2.0979855364233278E7,
  31. "msgRateRedeliver" : 0.0,
  32. "consumerName" : "fe3c0",
  33. "availablePermits" : 950,
  34. "unackedMessages" : 0,
  35. "blockedConsumerOnUnackedMsgs" : false,
  36. "address" : "/10.73.210.249:60578",
  37. "connectedSince" : "2017-07-26 15:13:48.026-0700",
  38. "clientVersion" : "1.19-incubating-SNAPSHOT"
  39. } ],
  40. "msgDropRate" : 432.2390921571593
  41. }
  42. },
  43. "replication": {}
  44. }

pulsar-admin

Topic stats can be fetched using stats command.

  1. $ pulsar-admin non-persistent stats \
  2. non-persistent://test-tenant/ns1/tp1 \

REST API

GET/admin/v2/non-persistent/:tenant/:namespace/:topic/stats

Java

  1. String topic = "non-persistent://my-tenant/my-namespace/my-topic";
  2. admin.nonPersistentTopics().getStats(topic);

Get internal stats

It shows detailed statistics of a topic.

pulsar-admin

Topic internal-stats can be fetched using stats-internal command.

  1. $ pulsar-admin non-persistent stats-internal \
  2. non-persistent://test-tenant/ns1/tp1 \
  3. {
  4. "entriesAddedCounter" : 48834,
  5. "numberOfEntries" : 0,
  6. "totalSize" : 0,
  7. "cursors" : {
  8. "s1" : {
  9. "waitingReadOp" : false,
  10. "pendingReadOps" : 0,
  11. "messagesConsumedCounter" : 0,
  12. "cursorLedger" : 0,
  13. "cursorLedgerLastEntry" : 0
  14. }
  15. }
  16. }

REST API

GET/admin/v2/non-persistent/:tenant/:namespace/:topic/internalStats

Java

  1. String topic = "non-persistent://my-tenant/my-namespace/my-topic";
  2. admin.nonPersistentTopics().getInternalStats(topic);

Create partitioned topic

Partitioned topics in Pulsar must be explicitly created. When creating a new partitioned topic you need to provide a name for the topic as well as the desired number of partitions.

pulsar-admin

  1. $ bin/pulsar-admin non-persistent create-partitioned-topic \
  2. non-persistent://my-tenant/my-namespace/my-topic \
  3. --partitions 4

REST API

PUT/admin/v2/non-persistent/:tenant/:namespace/:topic/partitions

Java

  1. String topicName = "non-persistent://my-tenant/my-namespace/my-topic";
  2. int numPartitions = 4;
  3. admin.nonPersistentTopics().createPartitionedTopic(topicName, numPartitions);

Get metadata

Partitioned topics have metadata associated with them that you can fetch as a JSON object. The following metadata fields are currently available:

FieldMeaning
partitionsThe number of partitions into which the topic is divided

pulsar-admin

  1. $ pulsar-admin non-persistent get-partitioned-topic-metadata \
  2. non-persistent://my-tenant/my-namespace/my-topic
  3. {
  4. "partitions": 4
  5. }

REST API

GET/admin/v2/non-persistent/:tenant/:namespace/:topic/partitions

Java

  1. String topicName = "non-persistent://my-tenant/my-namespace/my-topic";
  2. admin.nonPersistentTopics().getPartitionedTopicMetadata(topicName);

Unload topic

It unloads a topic.

pulsar-admin

Topic can be unloaded using unload command.

  1. $ pulsar-admin non-persistent unload \
  2. non-persistent://test-tenant/ns1/tp1 \

REST API

PUT/admin/v2/non-persistent/:tenant/:namespace/:topic/unload

Java

  1. String topic = "non-persistent://my-tenantmy-namespace/my-topic";
  2. admin.nonPersistentTopics().unload(topic);