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--mount
parameter, just execute the full command.
Becare the port conflict, you may want choice the different port like below winth HOST.
Now we know the broker URL is :$ docker run -it \
-p 16650:6650 \
-p 18080:8080 \
--mount source=pulsardata,target=/pulsar/data \
--mount source=pulsarconf,target=/pulsar/conf \
apachepulsar/pulsar:latest \
bin/pulsar standalone
pulsar://192.168.129.111:16650/
.
If it run successfully, we’ll see some INFO log to print standalone info :
And now you run the standalone pulsar container in foreground (run without2022-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}
{
"c-standalone-fw-localhost-8080" : {
"originalNumAssignments" : 0,
"finalNumAssignments" : 0,
"instancesAdded" : 0,
"instancesRemoved" : 0,
"instancesUpdated" : 0,
"alive" : true
}
}
-d
parameter).Pub-Sub Test
Using pulsar-client tool in pulsar binary directory : ```shellconsume 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”
If it run successfully, we'll see some INFO log from the foreground container :
```shell
- New connection from /192.1.216.107:51294
- [/192.1.216.107:51294][persistent://public/default/test] Creating producer. producerId=0
- [/192.1.216.107:51294] persistent://public/default/test configured with schema false
- [/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}
- [PersistentTopic{topic=persistent://public/default/test}][standalone-0-2] Closing producer on cnx /192.1.216.107:51294. producerId=0
- Closed connection from /192.1.216.107:51291
... omit date info just show the core log...
Get the topic statistics
More API [4].
$ curl http://localhost:18080/admin/v2/persistent/public/default/test/stats | python -m json.tool
$ 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