Socket
Socket
Sign inDemoInstall

github.com/arcanericky/gcppubsubdemo

Package Overview
Dependencies
2
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/arcanericky/gcppubsubdemo

Package gcppubsubdemo is a tool for teaching and learning Google Cloud Platform's pub/sub API. This package is not meant to be used as an API but it is documented like one for instructional purposes. Quick usage examples for the package are shown below. For more information, see the documentation for the individual items. To use the API for publishing, call the GetPublisher function to obtain a Publisher function to call. Call the Publisher function giving the data to publish as the only parameter. To shut down the Publisher, call the Publisher function with nil as the parameter. Failing to do so will leave pub/sub code and network operations initialized. Subscribe to a topic by callng the Subscribe function, giving it a callback to execute when data is received. The callback should return true when it no longer wants to retrieve messages and shut down the subscription. Basic logging is implemented using the standard log package. Logging is disabled by default. When enabled with a call to LogLevel(), log output goes to os.Stderr but can be redirected by using LogOutput().


Version published

Readme

Source

Google Cloud Platform Pub/Sub

A project for learning and teaching pub/sub using Go in the Google Cloud Platform using Google's Pubsub package

Build Status GoDoc PRs Welcome


Purpose

TL;DR: If you are not a software developer, find another project.

There is no normal end user functionality provided. It's a project implemented using Go to build demonstration executables so the user can inspect the source code and run the executables to learn how to implement simple pub/sub functionality in Google Cloud Platform using Google's Pub/Sub package.

Building

$ go build -o gcppubsubdemo ./cmd/...

Pub/Sub Emulator

This project is meant to be used with the GCP Pub/Sub emulator. See these installation and execution instructions to get it installed and running.

In summary, install with

$ gcloud components install pubsub-emulator
$ gcloud components update

Execute with

$ gcloud beta emulators pubsub start --project=PUBSUB_PROJECT_ID

or

$ gcloud beta emulators pubsub start --host-port 127.0.0.1:9999

Executing

Quick Start for gcppubsubdemo

In another terminal, execute the publisher with

$ $(gcloud beta emulators pubsub env-init)
$ gcppubsubdemo publish

And in another terminal, execute the subscriber with

$ $(gcloud beta emulators pubsub env-init)
$ gcppubsubdemo subscribe

The default for both the publish and subscribe commands are to publish and receive data continuously. Use Ctrl-C to stop execution noting that in this case, the subscription ID and topics will remain created in the pub/sub emulator. When using the --once option these will be removed upon exit.

The --verbose option is particularly useful when learning how the code flows. It enables DEBUG and TRACE level logging useful for following the code logic.

Help

There are command line options for gcppubsubdemo. Use the --help flag to find them.

Examples

$ gcppubsubdemo --help
$ gcppubsubdemo subscribe --help
$ gcppubsubdemo publish --help

API and Design

The design of gcppubsubcdemo consists of command-line user interface code in cmd/ driven with Cobra. This code in turn drives the gcppubsubdemo package (API) in the project root. This is mainly to illustrate good architecture. Because the core pub/sub functionality is implemented as an API it can allow for re-use in other projects. However, I don't plan on this package ever evolving past the 0.0.x version because this repository is for learning and this pub/sub code should be implemented natively by other developers. You have been warned when I break the API.

Documentation

This project is documented with this README.md, scattered code comments, and full GoDoc documentation as if it was a viable API. This is done to show good practices.

Contributing

Contributions and bug fixes (and there are bugs because I also used this code to learn) are welcome. When contributing new functionality, try to keep the code straightforward because the purpose of this project is to help fellow developers learn. Try to use functions rather than methods. Keep dependency injection to a minimum, etc.

Some areas for consideration:

  • Defect remedies (bug fixes)
  • Pub/Sub API usage improvements
  • Unit Tests (as long as the code remains readable by novice Gophers)
  • Additional command line options to expose more pub/sub functionality
  • Documentation corrections or additional information

Inspiration

I had to learn this pubsub package for my day job. For me, learning means writing and experimenting with code snippets. After I learned the minimal amount to get the job done, I spent my evenings pulling these code snippets together into self-contained meaningful project to help others. This project is the result.

FAQs

Last updated on 29 Jul 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc