Skip to main content
This quickstart guide gets you up and running with Apache Pulsar in standalone mode. You’ll start a Pulsar service, create a topic, and send and receive messages using both the CLI and client libraries.
Standalone mode runs all Pulsar components (broker, BookKeeper, and ZooKeeper) in a single JVM process. It’s perfect for development and testing, but not recommended for production use.

Prerequisites

Before you begin, ensure you have:
  • Java 17 or 21 installed (see Java version requirements)
  • Docker installed (alternative to local installation)
  • Basic understanding of pub-sub messaging concepts

Start Pulsar in standalone mode

The fastest way to try Pulsar is using Docker. Skip the installation and jump straight to running Pulsar.
# Pull the latest Pulsar image
docker pull apachepulsar/pulsar:latest

# Start Pulsar in standalone mode
docker run -it -p 6650:6650 -p 8080:8080 \
  apachepulsar/pulsar:latest \
  bin/pulsar standalone
Pulsar will start and display logs indicating that the broker is ready:
INFO  org.apache.pulsar.broker.PulsarService - messaging service is ready
The standalone service runs on:
  • Broker service: pulsar://localhost:6650
  • HTTP service: http://localhost:8080

Publish and consume messages with CLI

Let’s start by using Pulsar’s command-line tools to send and receive messages.
1

Open a new terminal for the consumer

Start a consumer that will listen for messages on a topic:
docker exec -it <container-id> bin/pulsar-client consume \
  persistent://public/default/my-topic \
  --subscription-name my-subscription \
  --num-messages 0
The consumer will start and wait for messages. The --num-messages 0 flag means it will run indefinitely.
2

Open another terminal for the producer

In a new terminal, send messages to the topic:
docker exec -it <container-id> bin/pulsar-client produce \
  persistent://public/default/my-topic \
  --messages "Hello Pulsar" \
  --num-produce 10
This sends 10 messages to the topic.
3

View the messages

Switch back to the consumer terminal. You should see the messages being received:
----- got message -----
key:[null], properties:[], content:Hello Pulsar
----- got message -----
key:[null], properties:[], content:Hello Pulsar
...

Create your first producer

Now let’s write code to produce messages. Here are examples using different Pulsar client libraries:
import org.apache.pulsar.client.api.PulsarClient;
import org.apache.pulsar.client.api.Producer;
import org.apache.pulsar.client.api.Schema;

public class ProducerExample {
    public static void main(String[] args) throws Exception {
        // Create a Pulsar client instance
        PulsarClient client = PulsarClient.builder()
                .serviceUrl("pulsar://localhost:6650")
                .build();

        // Create a producer on a topic
        Producer<String> producer = client.newProducer(Schema.STRING)
                .topic("persistent://public/default/my-topic")
                .create();

        // Send 10 messages to the topic
        for (int i = 0; i < 10; i++) {
            String message = "Message " + i;
            producer.send(message);
            System.out.println("Sent: " + message);
        }

        // Close the producer and client
        producer.close();
        client.close();
    }
}
These examples use the actual Pulsar client API from the source code at pulsar-client-api/src/main/java/org/apache/pulsar/client/api/PulsarClient.java.

Create your first consumer

Now let’s create a consumer to receive the messages:
import org.apache.pulsar.client.api.*;

public class ConsumerExample {
    public static void main(String[] args) throws Exception {
        // Create a Pulsar client instance
        PulsarClient client = PulsarClient.builder()
                .serviceUrl("pulsar://localhost:6650")
                .build();

        // Create a consumer on a topic with a subscription
        Consumer<String> consumer = client.newConsumer(Schema.STRING)
                .topic("persistent://public/default/my-topic")
                .subscriptionName("my-subscription")
                .subscribe();

        // Receive and process messages
        while (true) {
            Message<String> message = consumer.receive();
            System.out.println("Got message: " + message.getValue());
            consumer.acknowledge(message);
        }
    }
}

Understanding topics and subscriptions

In Pulsar, topics are named channels for transmitting messages from producers to consumers. Subscriptions are named configurations that determine how consumers consume messages from topics.

Topic naming

The complete topic name format is:
persistent://tenant/namespace/topic
  • persistent: Message durability (persistent or non-persistent)
  • tenant: Logical grouping for multi-tenancy (default: public)
  • namespace: Administrative unit within a tenant (default: default)
  • topic: The actual topic name

Subscription types

Pulsar supports multiple subscription types:

Exclusive

Only one consumer can subscribe. Guarantees message ordering.

Shared

Multiple consumers share the subscription. Messages are distributed round-robin.

Failover

Multiple consumers, but only one is active. Provides high availability.

Key_Shared

Messages with the same key go to the same consumer. Combines ordering and parallelism.

Next steps

Installation

Learn how to install Pulsar for production environments

Concepts

Dive deeper into Pulsar’s architecture and concepts
Remember to stop your standalone Pulsar instance when you’re done:
  • Press Ctrl+C in the terminal running Pulsar
  • For Docker: docker stop <container-id>

Build docs developers (and LLMs) love