Internal tools to run & simulation Pub/Sub on localhost
- Install Docker
https://docs.docker.com/desktop/install/linux-install/
https://docs.docker.com/desktop/install/mac-install/
- Setup / Export environment variables (Linux/Mac)
export PUBSUB_EMULATOR_HOST=localhost:8085
export PUBSUB_PROJECT_ID=project1
- Install pubsub-emulator-tools
go install github.com/opannapo/pubsub-emulator-tools@latest _ _ _ _ _ _
_ __ _ _| |__ ___ _ _| |__ ___ _ __ ___ _ _| | __ _| |_ ___ _ __ | |_ ___ ___ | |___
| '_ \| | | | '_ \/ __| | | | '_ \ _____ / _ | '_ ' _ \| | | | |/ _' | __/ _ \| '_______| __/ _ \ / _ \| / __|
| |_) | |_| | |_) \__ | |_| | |_) |_____| __| | | | | | |_| | | (_| | || (_) | | |_____| || (_) | (_) | \__ \
| .__/ \__,_|_.__/|___/\__,_|_.__/ \___|_| |_| |_|\__,_|_|\__,_|\__\___/|_| \__\___/ \___/|_|___/
|_| v:v1.0.4 PID:112436
------------------------------------------------------------------------------------------
Emulator Application Simulator
------------------------------------------------------------------------------------------
[1] setup-emulator-compose [2] topic-create [8] start-pub-http
[3] topic-list [9] start-sub-cli
[4] topic-delete
[5] subscription-create
[6] subscription-list
[7] subscription-delete
Action number : _ _ _ _ _ _
_ __ _ _| |__ ___ _ _| |__ ___ _ __ ___ _ _| | __ _| |_ ___ _ __ | |_ ___ ___ | |___
| '_ \| | | | '_ \/ __| | | | '_ \ _____ / _ | '_ ' _ \| | | | |/ _' | __/ _ \| '_______| __/ _ \ / _ \| / __|
| |_) | |_| | |_) \__ | |_| | |_) |_____| __| | | | | | |_| | | (_| | || (_) | | |_____| || (_) | (_) | \__ \
| .__/ \__,_|_.__/|___/\__,_|_.__/ \___|_| |_| |_|\__,_|_|\__,_|\__\___/|_| \__\___/ \___/|_|___/
|_| v:v1.0.4 PID:112436
------------------------------------------------------------------------------------------
Emulator Application Simulator
------------------------------------------------------------------------------------------
[1] setup-emulator-compose [2] topic-create [8] start-pub-http
[3] topic-list [9] start-sub-cli
[4] topic-delete
[5] subscription-create
[6] subscription-list
[7] subscription-delete
Action number : 1[setup-emulator-compose] project ID : project1
[setup-emulator-compose] port : 8085 Docker Output :
Docker Compose created at /Users/lion/.tmp-emulator/docker-compose.yml
WARN[0000] /Users/lion/.tmp-emulator/docker-compose.yml: `version` is obsolete
[+] Running 5/7
⠏ pubsub-emulator [⣿⣿⣿⣿⣿⣀] 180.8MB / 463.7MB Pulling 38.0s
✔ 5de87e84afee Pull complete 10.0s
✔ 34c68e5535f6 Pull complete 10.0s
✔ 819e44463e51 Pull complete 10.0s
✔ 5f0923bf6e65 Pull complete 10.0s
✔ 65b291c23283 Pull complete 10.0s
⠧ 864c6a15293c Downloading [=================> ] 149.4MB/432.3MB 25.8sWARN[0000] /Users/lion/.tmp-emulator/docker-compose.yml: `version` is obsolete
[+] Running 7/7
✔ pubsub-emulator Pulled 87.8s
✔ 5de87e84afee Pull complete 10.0s
✔ 34c68e5535f6 Pull complete 10.0s
✔ 819e44463e51 Pull complete 10.0s
✔ 5f0923bf6e65 Pull complete 10.0s
✔ 65b291c23283 Pull complete 10.0s
✔ 864c6a15293c Pull complete 75.1s
[+] Running 2/2
✔ Container pubsub-emulator Started 1.2s
! pubsub-emulator The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested 0.0s
Continue [Y/N] ?
Check your docker
lion@M1 ~ % docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3371b9dcc573 google/cloud-sdk:emulators "/bin/bash -c 'gclou…" 4 minutes ago Up 4 minutes 0.0.0.0:8085->8085/tcp pubsub-emulator
lion@M1 ~ % Check via browser: http://localhost:8085/
_ _ _ _ _ _
_ __ _ _| |__ ___ _ _| |__ ___ _ __ ___ _ _| | __ _| |_ ___ _ __ | |_ ___ ___ | |___
| '_ \| | | | '_ \/ __| | | | '_ \ _____ / _ | '_ ' _ \| | | | |/ _' | __/ _ \| '_______| __/ _ \ / _ \| / __|
| |_) | |_| | |_) \__ | |_| | |_) |_____| __| | | | | | |_| | | (_| | || (_) | | |_____| || (_) | (_) | \__ \
| .__/ \__,_|_.__/|___/\__,_|_.__/ \___|_| |_| |_|\__,_|_|\__,_|\__\___/|_| \__\___/ \___/|_|___/
|_| v:v1.0.4 PID:112436
------------------------------------------------------------------------------------------
Emulator Application Simulator
------------------------------------------------------------------------------------------
[1] setup-emulator-compose [2] topic-create [8] start-pub-http
[3] topic-list [9] start-sub-cli
[4] topic-delete
[5] subscription-create
[6] subscription-list
[7] subscription-delete
Action number : 2[topic-create] topic name : test-topicOutput :
[topic-create] topic name : test-topic
2024/07/21 00:23:52 Topic Create
create topic test-topic
Topic projects/opannapo-project-id/topics/test-topic created.
Continue [Y/N] ? _ _ _ _ _ _
_ __ _ _| |__ ___ _ _| |__ ___ _ __ ___ _ _| | __ _| |_ ___ _ __ | |_ ___ ___ | |___
| '_ \| | | | '_ \/ __| | | | '_ \ _____ / _ | '_ ' _ \| | | | |/ _' | __/ _ \| '_______| __/ _ \ / _ \| / __|
| |_) | |_| | |_) \__ | |_| | |_) |_____| __| | | | | | |_| | | (_| | || (_) | | |_____| || (_) | (_) | \__ \
| .__/ \__,_|_.__/|___/\__,_|_.__/ \___|_| |_| |_|\__,_|_|\__,_|\__\___/|_| \__\___/ \___/|_|___/
|_| v:v1.0.4 PID:112436
------------------------------------------------------------------------------------------
Emulator Application Simulator
------------------------------------------------------------------------------------------
[1] setup-emulator-compose [2] topic-create [8] start-pub-http
[3] topic-list [9] start-sub-cli
[4] topic-delete
[5] subscription-create
[6] subscription-list
[7] subscription-delete
Action number : 3Output :
2024/07/21 00:52:04 Topic List
2024/07/21 00:52:04 projects/opannapo-project-id/topics/abc
2024/07/21 00:52:04 projects/opannapo-project-id/topics/abcd
2024/07/21 00:52:04 projects/opannapo-project-id/topics/def
2024/07/21 00:52:04 projects/opannapo-project-id/topics/test-topic
Continue [Y/N] ? _ _ _ _ _ _
_ __ _ _| |__ ___ _ _| |__ ___ _ __ ___ _ _| | __ _| |_ ___ _ __ | |_ ___ ___ | |___
| '_ \| | | | '_ \/ __| | | | '_ \ _____ / _ | '_ ' _ \| | | | |/ _' | __/ _ \| '_______| __/ _ \ / _ \| / __|
| |_) | |_| | |_) \__ | |_| | |_) |_____| __| | | | | | |_| | | (_| | || (_) | | |_____| || (_) | (_) | \__ \
| .__/ \__,_|_.__/|___/\__,_|_.__/ \___|_| |_| |_|\__,_|_|\__,_|\__\___/|_| \__\___/ \___/|_|___/
|_| v:v1.0.4 PID:112436
------------------------------------------------------------------------------------------
Emulator Application Simulator
------------------------------------------------------------------------------------------
[1] setup-emulator-compose [2] topic-create [8] start-pub-http
[3] topic-list [9] start-sub-cli
[4] topic-delete
[5] subscription-create
[6] subscription-list
[7] subscription-delete
Action number : 4Output
2024/07/26 11:09:18 projects/opannapo-project-id/topics/sub1-topic1
2024/07/26 11:09:18 projects/opannapo-project-id/topics/test1
2024/07/26 11:09:18 projects/opannapo-project-id/topics/test2
[topic-delete] topic name : test1
Topic test1 deleted.
Continue [Y/N] ? : Action number : 5Output
[subscription-create] subscription name : sub2
[subscription-create] topic name : sub2-topic2
Created subscription: projects/opannapo-project-id/subscriptions/sub2
Continue [Y/N] ? : Action number : 6Output:
2024/07/26 11:11:39 projects/opannapo-project-id/subscriptions/sub1
2024/07/26 11:11:39 projects/opannapo-project-id/subscriptions/sub2
Continue [Y/N] ? : Action number : 7Output:
2024/07/26 11:12:11 projects/opannapo-project-id/subscriptions/sub1
2024/07/26 11:12:11 projects/opannapo-project-id/subscriptions/sub2
[subscription-delete] subscription name : sub1
Subscription sub1 deleted.
Continue [Y/N] ? : Action number : 8Output:
[start-pub-http] port : 8080
[start-pub-http] subscription ID : sub2
[start-pub-http] topic : sub2-topic2
2024/07/26 11:16:42 Starting server on port 8080...Url : POST localhost:8080/publish
Payload :
{
"first_name":"John",
"last_name":"Doe"
}curl --location 'localhost:8080/publish' \
--header 'Content-Type: application/json' \
--data '{
"first_name":"John",
"last_name":"Doe"
}' Action number : 9Output:
[start-sub-cli] subscription ID : sub2
listening for messages ...[start-sub-cli] subscription ID : sub2
listening for messages ...
Received message: {
"first_name":"John1",
"last_name":"Doe1"
}
Received message: {
"first_name":"John2",
"last_name":"Doe2"
}| Item |
|---|
| Graceful Shutdown |
| Create Topic with configuration |
| Create Subscription with configuration |
| Proper error handling |