Skip to main content

Managing non-partitioned topics

You can use Pulsar's admin API to create and manage non-partitioned topics.

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


persistent://tenant/namespace/topic

Non-Partitioned topics resources​

Create​

Non-partitioned topics in Pulsar must be explicitly created. When creating a new non-partitioned topic you need to provide a name for the topic.

note

By default, after 60 seconds of creation, topics are considered inactive and deleted automatically to prevent from generating trash data. To disable this feature, set brokerDeleteInactiveTopicsEnabled to false. To change the frequency of checking inactive topics, set brokerDeleteInactiveTopicsFrequencySeconds to your desired value. For more information about these two parameters, see here.

pulsar-admin​

You can create non-partitioned topics using the create command and specifying the topic name as an argument. Here's an example:


$ bin/pulsar-admin topics create \
persistent://my-tenant/my-namespace/my-topic

note

It's only allowed to create non partitioned topic of name contains suffix '-partition-' followed by numeric value like 'xyz-topic-partition-10', if there's already a partitioned topic with same name, in this case 'xyz-topic', and has number of partition larger then that numeric value in this case 11(partition index is start from 0). Else creation of such topic will fail.

REST API​

PUT /admin/v2/:schema/:tenant/:namespace/:topic

Java​


String topicName = "persistent://my-tenant/my-namespace/my-topic";
admin.topics().createNonPartitionedTopic(topicName);

Delete​

pulsar-admin​

Non-partitioned topics can be deleted using the delete command, specifying the topic by name:


$ bin/pulsar-admin topics delete \
persistent://my-tenant/my-namespace/my-topic

REST API​

DELETE /admin/v2/:schema/:tenant/:namespace/:topic

Java​


admin.topics().delete(persistentTopic);

List​

It provides a list of topics existing under a given namespace.

pulsar-admin​


$ pulsar-admin topics list tenant/namespace
persistent://tenant/namespace/topic1
persistent://tenant/namespace/topic2

REST API​

GET /admin/v2/:schema/:tenant/:namespace

Java​


admin.topics().getList(namespace);

Stats​

It shows current statistics of a given topic. Here's an example payload:

The following stats are available:

StatDescription
msgRateInThe sum of all local and replication publishers’ publish rates in messages per second
msgThroughputInSame as msgRateIn but in bytes per second instead of messages per second
msgRateOutThe sum of all local and replication consumers’ dispatch rates in messages per second
msgThroughputOutSame as msgRateOut but in bytes per second instead of messages per second
averageMsgSizeAverage message size, in bytes, from this publisher within the last interval
storageSizeThe sum of the ledgers’ storage size for this topic
publishersThe list of all local publishers into the topic. There can be anywhere from zero to thousands.
producerIdInternal identifier for this producer on this topic
producerNameInternal identifier for this producer, generated by the client library
addressIP address and source port for the connection of this producer
connectedSinceTimestamp this producer was created or last reconnected
subscriptionsThe list of all local subscriptions to the topic
my-subscriptionThe name of this subscription (client defined)
msgBacklogThe count of messages in backlog for this subscription
msgBacklogNoDelayedThe count of messages in backlog without delayed messages for this subscription
typeThis subscription type
msgRateExpiredThe rate at which messages were discarded instead of dispatched from this subscription due to TTL
consumersThe list of connected consumers for this subscription
consumerNameInternal identifier for this consumer, generated by the client library
availablePermitsThe number of messages this consumer has space for in the client library’s listen queue. A value of 0 means the client library’s queue is full and receive() isn’t being called. A nonzero value means this consumer is ready to be dispatched messages.
replicationThis section gives the stats for cross-colo replication of this topic
replicationBacklogThe outbound replication backlog in messages
connectedWhether the outbound replicator is connected
replicationDelayInSecondsHow long the oldest message has been waiting to be sent through the connection, if connected is true
inboundConnectionThe IP and port of the broker in the remote cluster’s publisher connection to this broker
inboundConnectedSinceThe 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.

pulsar-admin​

The stats for the topic and its connected producers and consumers can be fetched by using the stats command, specifying the topic by name:


$ pulsar-admin topics stats \
persistent://test-tenant/namespace/topic \
--get-precise-backlog

REST API​

GET /admin/v2/:schema/:tenant/:namespace/:topic/stats

Java​


admin.topics().getStats(persistentTopic, false /* is precise backlog */);