Skip to main content
Version: Next

Get started

This guide walks you through the quickest way to get started with the following Pulsar admin APIs to manage topics:

  • Java admin API

  • Go admin API (coming soon)

  • REST API

This tutorial guides you through every step of using Java admin API to manage topics. It includes the following steps:

  1. Initiate a Pulsar Java client.

  2. Create a partitioned topic

  3. Update the number of a partition.

  4. Produce messages to the topic.

  5. Check the stats of the topic.

  6. Delete the topic.

Prerequisites

Steps

  1. Initiate a Pulsar Java client in your Java project.

    Input

    String url = "http://localhost:8080";
    PulsarAdmin admin = PulsarAdmin.builder()
    .serviceHttpUrl(url)
    .build();
  2. Create a partitioned topic test-topic-1 with 4 partitions.

    Input

    admin.topics().createPartitionedTopic("persistent://public/default/test-topic-1", 4);
  3. Update the number of the partition to 5.

    Input

    admin.topics().updatePartitionedTopic("test-topic-1", 5);
  4. Produce some messages to the topic test-topic-1.

    Input

    PulsarClient client = PulsarClient.builder()
    .serviceUrl("pulsar://localhost:6650")
    .build();

    Producer<String> producer = client.newProducer(Schema.STRING)
    .topic(topic)
    .blockIfQueueFull(true)
    .create();

    for (int i = 0; i < 100; ++i) {
    producer.newMessage().value("test").send();
    }
    producer.close();
    client.close();
  5. Check the stats of the topic test-topic-1.

    Input

    admin.topics().getPartitionedStats("persistent://public/default/test-topic-1", false)
  6. Delete the topic test-topic-1.

    Input

    admin.topics().deletePartitionedTopic("test-topic-1");
Was this helpful?