What can you get from this article:

  • For local testing ,we can run Pulsar in standalone mode within a Docker container. [1]

    Prerequisites

    Deploy enviroment

  • Docker enviroment: I’m using version 20.10.2

  • Pull pulsar image [2]:I’m using docker pull apachepulsar/pulsar:latest
  • Download an pulsar binary verison just for test the running status with container.

    Run in Standalone mode within Docker container

    Run

    Run in any directory, for now we can ignore the --mountparameter, just execute the full command.
    Becare the port conflict, you may want choice the different port like below winth HOST.
    1. $ docker run -it \
    2. -p 16650:6650 \
    3. -p 18080:8080 \
    4. --mount source=pulsardata,target=/pulsar/data \
    5. --mount source=pulsarconf,target=/pulsar/conf \
    6. apachepulsar/pulsar:latest \
    7. bin/pulsar standalone
    Now we know the broker URL is : pulsar://192.168.129.111:16650/.
    If it run successfully, we’ll see some INFO log to print standalone info :
    1. 2022-03-18T08:25:29,238+0000 [worker-scheduler-0] INFO org.apache.pulsar.functions.worker.SchedulerManager - Schedule summary - execution time: 0.096182383 sec | total unassigned: 0 | stats: {"Added": 0, "Updated": 0, "removed": 0}
    2. {
    3. "c-standalone-fw-localhost-8080" : {
    4. "originalNumAssignments" : 0,
    5. "finalNumAssignments" : 0,
    6. "instancesAdded" : 0,
    7. "instancesRemoved" : 0,
    8. "instancesUpdated" : 0,
    9. "alive" : true
    10. }
    11. }
    And now you run the standalone pulsar container in foreground (run without -dparameter).

    Pub-Sub Test

    Using pulsar-client tool in pulsar binary directory : ```shell

    consume it

    bin/pulsar-client —url pulsar://192.168.129.111:16650/ consume \ persistent://public/default/test \ -n 100 \ -s “consumer-test” \ -t “Exclusive”

produce something

bin/pulsar-client —url pulsar://192.168.129.111:16650/ produce \ persistent://public/default/test \ -n 1 \ -f /etc/hosts

produce simple messages

bin/pulsar-client —url pulsar://192.168.129.111:16650/ produce \ persistent://public/default/test \ -n 3 \ -m “hello pulsar”

  1. If it run successfully, we'll see some INFO log from the foreground container :
  2. ```shell
  3. - New connection from /192.1.216.107:51294
  4. - [/192.1.216.107:51294][persistent://public/default/test] Creating producer. producerId=0
  5. - [/192.1.216.107:51294] persistent://public/default/test configured with schema false
  6. - [/192.1.216.107:51294] Created new producer: Producer{topic=PersistentTopic{topic=persistent://public/default/test}, client=/192.1.216.107:51294, producerName=standalone-0-2, producerId=0}
  7. - [PersistentTopic{topic=persistent://public/default/test}][standalone-0-2] Closing producer on cnx /192.1.216.107:51294. producerId=0
  8. - Closed connection from /192.1.216.107:51291
  9. ... omit date info just show the core log...

Get the topic statistics

More API [4].

  1. $ curl http://localhost:18080/admin/v2/persistent/public/default/test/stats | python -m json.tool
  2. $ curl http://localhost:18080/admin/v2/clusters

Reference

[1] Set up a standalone Pulsar in Docker: https://pulsar.apache.org/docs/en/standalone-docker/
[2] Pulsar Images in Docker Hub: https://hub.docker.com/r/apachepulsar/pulsar/tags
[3] 直播回顾|TGIP-CN 035: Apache Pulsar 动手实战第二期:容器部署实战 https://mp.weixin.qq.com/s/pccPcm4kMQVJaAk3p4GEqg
[4] Pulsar Admin REST API (v2) : https://pulsar.apache.org/admin-rest-api/?version=2.9.1&apiversion=v2