pubsub_cli is a super handy Pub/Sub CLI which lets you publish / subscribe Pub/Sub message right away!
$ brew tap k-yomo/pubsub_cli
$ brew install pubsub_cli
$ go install github.com/k-yomo/pubsub_cli
- If you want to use pubsub_cli for Pub/Sub Emulator, make sure the emulator is running before executing commands.
$ gcloud beta emulators pubsub start --host-port=0.0.0.0:8085
Usage:
pubsub_cli [command]
Available Commands:
help Help about any command
publish publish Pub/Sub message
subscribe subscribe Pub/Sub topics
create_topic create Pub/Sub topic
create_subscription create Pub/Sub subscription
register_push register Pub/Sub push endpoint
connect connect remote topics to local topics
Flags:
-c, --cred-file string gcp credential file path (You can also set 'GOOGLE_APPLICATION_CREDENTIALS' to env variable)
--help help for pubsub_cli
-h, --host string emulator host (You can also set 'PUBSUB_EMULATOR_HOST' to env variable)
-p, --project string gcp project id (You can also set 'GCP_PROJECT_ID' to env variable)
※ When both of --host and --cred-file are set, emulator host will be prioritised for safety purpose.
You need to be authenticated to execute pubsub_cli commands for real GCP Project. Recommended ways are described below.
- use your own credential by execution
gcloud auth application-default login
- use service account's credentials json by setting option
--cred-file
or env variableGOOGLE_APPLICATION_CREDENTIALS
For more detail and about the other ways to authenticate, please refer to official doc.
$ gcloud auth application-default login
$ pubsub_cli publish test_topic '{"key":"value"}' -a key=value -p your_gcp_project
- publish a message to the topic (create if not exist)
$ pubsub_cli publish new_topic '{"topic":"will be created"}' --create-if-not-exist -p your_gcp_project
- subscribe topics
$ pubsub_cli subscribe test_topic another_topic -c credentials.json -p your_gcp_project
- subscribe all
$ pubsub_cli subscribe all -c credentials.json -p your_gcp_project
$ pubsub_cli create_topic topic_1 topic_2 --host=localhost:8085 -p emulator
$ pubsub_cli cs test_topic test_topic_sub --create-if-not-exist -h localhost:8085 -p emulator
$ pubsub_cli register_push test_topic http://localhost:1323/subscribe -h localhost:8085 -p emulator
connect
command is useful to register push subscriptions with local endpoint for real topics on GCP.
- connect topics
$ pubsub_cli connect your_gcp_project topic1 topic2 -host localhost:8085 -p emulator
- connect all
$ pubsub_cli connect your_gcp_project all -h localhost:8085 -p emulator
- Created topics won't be deleted automatically.
- Unused subscriptions will be deleted in 24 hours.