pubsubc
A simple command-line client for Google Cloud Pub/Sub.
Unlike the gcloud pubsub
utility, pubsubc
:
- Supports the Pub/Sub emulator
- Provides a continuous subscribe command - to see all messages as they come in
Since this was originally created as a learning exercise for integrating to Pub/Sub, the source code should be simple enough for you to copy and adapt into your own application.
Contents
- Intro
- Installation
- Direct
- Bundler
- Usage
- Subscribe
- Publish message
- Publish generated messages
- Help info
- Contributing
- Development
- Pub/Sub emulator
- Pre-push hook
- Release
Intro
Features:
- Subscribe to a topic, continuously logging all messages as they arrive
- Publish a string message to a topic (creating a subscription automatically)
- Publish automatically-generated messages continuously at a given interval
- Supports connecting to either a local emulator or the remote real Pub/Sub
Installation
The executable is distributed through RubyGems.
Direct
You can install it to your system directly using:
gem install pubsubc
And then if you're using rbenv:
rbenv rehash
You can then run it with:
pubsubc
Bundler
Or, just add it to the Gemfile
of your project:
gem 'pubsubc'
And then run it with:
bundle exec pubsubc
Usage
Subscribe
To subscribe and continuously log all messages from the topic:
pubsubc sub
Publish message
To publish a single message to the topic:
pubsubc pub msg "G'day"
Publish generated messages
To publish a generated message to the topic every second:
pubsubc pub gen --interval 1000
Help info
Output of pubsubc --help
:
Usage:
pubsubc [OPTIONS] SUBCOMMAND [ARG] ...
A simple command-line client for Google Cloud Pub/Sub.
Created as a learning exercise, but also useful since the 'gcloud pubsub' commands don't support the emulator, and it doesn't provide a continuous subscribe command.
To clean up:
gcloud pubsub topics delete my-topic
gcloud pubsub subscriptions delete my-subscription
Parameters:
SUBCOMMAND subcommand
[ARG] ... subcommand arguments
Subcommands:
pub Publishing messages to the topic
sub Subscribe to messages on the topic
shell Get a Ruby shell to interact with Pub/Sub
Options:
--topic TOPIC_NAME The name of the Pub/Sub topic (default: "my-topic")
--subscription SUBSCRIPTION_NAME The name of the Pub/Sub subscription within the topic (default: "my-subscription")
--remote Connect to the real Pub/Sub, rather than a local Pub/Sub emulator
--emulator-host EMULATOR_HOST The host and port of the Pub/Sub emulator (default: $PUBSUB_EMULATOR_HOST, or "localhost:8085")
-h, --help print help
Suffix --help
to any subcommand to see the usage info for it.
Contributing
Pull requests welcome! =)
However, I don't intend to duplicate functionality that exists in the gcloud pubsub
utility, unless it's an improvement over what's in that.
Development
Pub/Sub emulator
To run the Pub/Sub emulator (with Docker):
docker-compose up -d pubsub-emulator
Pre-push hook
This hook runs style checks and tests.
To set up the pre-push hook:
echo -e "#\!/bin/bash\n\$(dirname \$0)/../../auto/pre-push-hook" > .git/hooks/pre-push
chmod +x .git/hooks/pre-push
Release
To release a new version:
auto/release/update-version && auto/release/tag && auto/release/publish
This takes care of the whole process:
- Incrementing the version number (the patch number by default)
- Tagging & pushing commits
- Publishing the gem to RubyGems
- Creating a draft GitHub release
To increment the minor or major versions instead of the patch number, run auto/release/update-version
with --minor
or --major
.