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 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.Open a new terminal for the consumer
Start a consumer that will listen for messages on a topic:The consumer will start and wait for messages. The
--num-messages 0 flag means it will run indefinitely.Open another terminal for the producer
In a new terminal, send messages to the topic:This sends 10 messages to the topic.
Create your first producer
Now let’s write code to produce messages. Here are examples using different Pulsar client libraries: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: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: 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