gcloud-pubsub-emulator

command module
v0.0.0-...-8734149 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2020 License: BSD-3-Clause Imports: 8 Imported by: 0

README

Adds push subscription

; to separate topic;subscription;subscription;subscription
| to separate topic;subscription|push_endpoint;subscription|push_endpoint pull and push subscriptions can be mixed

gcloud-pubsub-emulator

This repository contains the Docker configuration for Google's PubSub emulator. It's mainly the dockerization and documentation of https://github.com/prep/pubsubc

Installation

A pre-built Docker container is available for Docker Hub:

docker run --rm -ti -p 8681:8681 messagebird/gcloud-pubsub-emulator:latest

Or, you can build this repository yourself:

docker build -t gcloud-pubsub-emulator:latest .
docker run --rm -ti -p 8681:8681 gcloud-pubsub-emulator:latest

Usage

After you've ran the above-mentioned docker run command, you should be able to use any app that has PubSub implemented and point it to your Docker container by specifying the PUBSUB_EMULATOR_HOST environment variable.

env PUBSUB_EMULATOR_HOST=localhost:8681 ./myapp

or

export PUBSUB_EMULATOR_HOST=localhost:8681
./myapp
Automatic topic and subscription creation

This image also provides the ability to create topics and subscriptions in projects on startup by specifying the PUBSUB_PROJECT environment variable with a sequentual number appended to it, starting with 1. The format of the environment variable is relatively simple:

PROJECTID,TOPIC1,TOPIC2:SUBSCRIPTION1:SUBSCRIPTION2,TOPIC3:SUBSCRIPTION3

A comma-separated list where the first item is the project ID and the rest are topics. The topics themselves are colon-separated where the first item is the topic ID and the rest are subscription IDs. A topic doesn't necessarily need to specify subscriptions.

For example, if you have project ID company-dev, with topic invoices that has a subscription invoice-calculator, another topic chats with subscriptions slack-out and irc-out and a third topic notifications without any subscriptions, you'd define it this way:

PUBSUB_PROJECT1=company-dev,invoices:invoice-calculator,chats:slack-out:irc-out,notifications

So the full command would look like:

docker run --rm -ti -p 8681:8681 -e PUBSUB_PROJECT1=company-dev,invoices:invoice-calculator,chats:slack-out:irc-out,notifications messagebird/gcloud-pubsub-emulator:latest

If you want to define more projects, you'd simply add a PUBSUB_PROJECT2, PUBSUB_PROJECT3, etc.

wait-for, wait-for-it

If you're using this Docker image in a docker-compose setup or something similar, you might have leveraged scripts like wait-for or wait-for-it to detect when the PubSub service comes up before starting a container that depends on it being up. If you're not using the above-mentioned PUBSUB_PROJECT environment variable, you can simply check if port 8681 is available. If you do depend on one or more PUBSUB_PROJECT environment variables, you should check for the availability of port 8682 as that one will become available once all the topics and subscriptions have been created.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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