DEV Community

Rahul Lokurte
Rahul Lokurte

Posted on

Getting Started with Apache Pulsar

Prerequisite

To run apache pulsar, you need to have the Docker installed on the system. You can download docker from https://docs.docker.com/docker-for-windows/install/

Getting Started

Note: Apache pulsar has a cluster and within cluster, we have tenants. Within Tenants, we have namespaces.

  1. Start the pulsar instance in Docker
docker run -it -p 6650:6650 -p 8080:8080 --mount source=pulsardata,target=/pulsar/data --mount source=pulsarconf,target=/pulsar/conf apachepulsar/pulsar:2.6.0 bin/pulsar standalone
Enter fullscreen mode Exit fullscreen mode
  1. Check the container id of the pulsar
docker ps -a
Enter fullscreen mode Exit fullscreen mode
  1. Execute into the container bash
docker exec -it <container-id> bash
Enter fullscreen mode Exit fullscreen mode
  1. Get the cluster list
bin/pulsar-admin clusters list
Enter fullscreen mode Exit fullscreen mode
  1. Get the tenant list
bin/pulsar-admin tenants list
Enter fullscreen mode Exit fullscreen mode
  1. Get the namespaces list
bin/pulsar-admin namespaces list <tenant-name>
Enter fullscreen mode Exit fullscreen mode
  1. Get the topics
bin/pulsar-admin topics list <tenant-name>/<namespace-name>
Enter fullscreen mode Exit fullscreen mode
  1. Create a topic
bin/pulsar-admin topics create-partitioned-topic persistent://public/default/test-topic -p 1
Enter fullscreen mode Exit fullscreen mode
  1. To produce a message to the topic
bin/pulsar-client produce persistent://public/default/test-topic --num-produce 1 --messages "Hello pulsar 1"
Enter fullscreen mode Exit fullscreen mode
  1. To Consume a message from the topic
bin/pulsar-client consume persistent://public/default/test-topic --num-messages 0 --subscription-name test-topic-sub --subscription-type Exclusive
Enter fullscreen mode Exit fullscreen mode

NOTE: All the above commands assume, you are working on default tenants and default namespaces.

Top comments (0)