create

Create an object.

Use this command to create Apache Pulsar objects such as subscriptions, topics, namespaces, tenants, and schemas. You can create four different types of topics:

  • persistent-topics
  • persistent-partitioned-topics
  • non-persistent-topics
  • non-persistent-partitioned-topics
Note: As shown in the examples, the path can be absolute or relative to the current directory.

Synopsis

create <createCommandArg> [createCommandArg Options]

create namespace

create namespace <NamespaceName> [ bundle <Int>|clusters <Cluster>]
Create a new namespace.
Example:
Relative path:
/instance1/cluster1> create namespace tenant1/namespace1 bundle <int> clusters <Cluster>

create schemas

create schemas <Topic> file <FilePath>
Create a schema definition associated with a topic.

create tenant

create tenant <TenantName> [admin-roles <String>|allowed-clusters <Cluster>]
Create a new tenant. Separate multiple administrative roles or allowed clusters using a comma.
Example:
Absolute path:
/> create tenant /instance1/cluster1/tenant1 admin-roles <Roles> allowed-clusters <Cluster>

create topic

create topic <Topic> [partitions <Number of Partitions>] [properties <Properties>]
Create a topic.
Examples:
Assume there is an instance "instance1", a cluster "cluster1", a tenant "tenant1", and a namespace "namespace1".
To create a topic, use the create topic command, followed by the topic path and name. To create a partitioned topic, add the partitions flag after the topic name, along with the number of partitions to use. To assign properties to the topic, add the properties flag, specifying properties as a comma-separated list of the form Prop1=value,Prop2=value.
The topic prefix determines whether the topic is persistent or non-persistent. The topic prefix can be left out, in which case the topic defaults to be created as a persistent topic. If included, the prefix must be either persistent:// or non-persistent://. The prefix should go before the topic path.
Absolute path, persistent, non-partitioned topic:
/> create topic /instance1/cluster1/tenant1/namespace1/topic1

/> create topic persistent://instance1/cluster1/tenant1/namespace1/topic1
Absolute path, non-persistent, non-partitioned topic:
/> create topic non-persistent://instance1/cluster1/tenant1/namespace1/topic1
Absolute path, persistent, partitioned topic:
/> create topic 

/instance1/cluster1/tenant1/namespace1/topic1 partitions 3

/> create topic persistent://instance1/cluster1/tenant1/namespace1/topic1 partitions 10
Absolute path, non-persistent, partitioned topic:
/> create topic non-persistent://instance1/cluster1/tenant1/namespace1/topic1 partitions 7
Relative path, persistent, non-partitioned topic:
/instance1/cluster1/tenant1> create topic persistent://namespace1/topic1

create subscription

create subscription <Subscription> message-id <Position> [properties <Properties>]
Create a subscription on a particular topic.
Examples:
Assume there is an instance "instance1", a cluster "cluster1", a tenant "tenant1", a namespace "namespace1", and a topic "topic1".
To create a subscription, use the create subscription command, followed by the subscription path and name. Specify the subscription's starting position in the message stream with the message-id flag (earliest starts the subscription at the earliest message in the topic, and latest starts the subscription at the latest message in the topic). To assign properties to the subscription, add the properties flag, specifying properties as a comma-separated list of the form Prop1=value,Prop2=value.
The topic prefix determines whether the topic is persistent or non-persistent. The topic prefix can be left out, in which case the topic defaults to a persistent topic. If included, the prefix must be either persistent:// or non-persistent://. The prefix should go before the topic path.
Absolute path, persistent topic, starting at the earliest message:
/> create subscription /instance1/cluster1/tenant1/namespace1/topic1/sub1 message-id earliest

/> create subscription persistent://instance1/cluster1/tenant1/namespace1/topic1/sub1 message-id earliest
Absolute path, non-persistent topic, starting at the latest message:
/> create subscription non-persistent://instance1/cluster1/tenant1/namespace1/topic1/sub1 message-id latest
Relative path, persistent topic, starting at the earliest message, and specifying subscription properties:
/instance1/cluster1/tenant1> create subscription persistent://namespace1/topic1/sub1 message-id earliest properties Prop1=A,Prop2=Z