Skip to content

Instantly share code, notes, and snippets.

@jiazhai
Last active March 15, 2021 06:39
Show Gist options
  • Save jiazhai/e1f0e828754b73ad7792b34d2449690c to your computer and use it in GitHub Desktop.
Save jiazhai/e1f0e828754b73ad7792b34d2449690c to your computer and use it in GitHub Desktop.
geo-tutorial.md

This is based on https://gist.github.com/jiazhai/1cd48ab6c8f6c3012c895df9746799b5

0. prepare a docker image

1, build it from source code:

mvn install -DskipTests -Pdocker   

2, or use docker pull

docker pull apachepulsar/pulsar-test-latest-version 

start all nodes:

docker-compose up

1. start some nodes working as client in each cluster.

  1. use get network alis for your docker instances:
docker network ls
  1. start a client, and config the broker address: a. start a docker instance
docker run --name client-beijing  -it --rm  --network geodemo_pulsar apachepulsar/pulsar-test-latest-version:latest /bin/bash

b. in this docker instance run this command to replace the broker address in client.conf

$ sed -i "s/localhost/broker-beijing/g" conf/client.conf

c. do the same a.b.steps for shanghai, and guangzhou cluster:

docker run --name client-shanghai  -it --rm  --network geodemo_pulsar apachepulsar/pulsar-test-latest-version:latest /bin/bash
sed -i "s/localhost/broker-shanghai/g" conf/client.conf

docker run --name client-guangzhou  -it --rm  --network geodemo_pulsar apachepulsar/pulsar-test-latest-version:latest /bin/bash
sed -i "s/localhost/broker-guangzhou/g" conf/client.conf

2. create tenants and namespace

choose 1 instance from above client-beijing / client-shanghai / client-guangzhou to create tenants an namespace.

bin/pulsar-admin tenants create my-tenant  --allowed-clusters beijing,shanghai,guangzhou
bin/pulsar-admin namespaces create my-tenant/my-namespace --clusters beijing,shanghai,guangzhou

3. verify messages send and receive.

a. in both client-shanghai and client-guangzhou, create a subscription for the test topic, they will wait receive messages from client-beijing in client-shanghai

bin/pulsar-client consume -s "sub-shanghai" my-tenant/my-namespace/t1 -n 0

in client-guangzhou

bin/pulsar-client consume -s "sub-guangzhou" my-tenant/my-namespace/t1 -n 0

b. in client-beijing, produce message to the topic

bin/pulsar-client produce  my-tenant/my-namespace/t1  --messages "hello-from-beijing-1" -n 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment