gcppubsub

package module
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2020 License: MIT Imports: 7 Imported by: 0

README

Google Cloud Platform Pubsub

A project for learning and teaching pubsub 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 pubsub functionality in Google Cloud Platform using Google's Pubsub package.

Building

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

Pubsub Emulator

This project is meant to be used with the GCP Pubsub 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 gcppubsub

In another terminal, execute the publisher with

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

And in another terminal, execute the subscriber with

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

Note 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 emulator. When using the --once option these will be removed upon exit.

Help

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

Examples

$ gcppubsub --help
$ gcppubsub subscribe --help
$ gcppubsub publish --help

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.

Some areas for consideration:

  • Defect remedies (bug fixes)
  • Pubsub API usage improvements
  • Unit Tests (as long as the code remains readable by novice Gophers)
  • Additional command line options to expose more pubsub functionality

Documentation

Overview

Package gcppubsub 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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Publish

func Publish(gcpName, topicName string, once bool, getData GetPubSubDataFunc) error

Publish publishes to a pub/sub topic given a Google Cloud Project name and a topic name. If the once flag is true, it will send exactly one message then exit. If false, it will continue to send messages until execution is interrupted or the callback returns true. The callback parameter must be set and is used to provide the data to be published and a flag to indicate whether it should cease sending messages.

If an error is encountered, it is returned.

func Subscribe

func Subscribe(gcpName, topicName, subscriptionID string, once bool) error

Subscribe subscribes and retrieves pub/sub messages from a given Google Cloud Project and topic. If the once flag is true, it will receive exactly one message then stop.

If an error is encountered, it is returned.

Types

type GetPubSubDataFunc

type GetPubSubDataFunc func() ([]byte, bool)

GetPubSubDataFunc is a function type used as a callback for getting data to publish

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL