Skip to content

A docker image `FROM google/cloud-sdk:alpine` that `gcloud beta emulators pubsub start`

License

Notifications You must be signed in to change notification settings

marcelcorso/gcloud-pubsub-emulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A docker image `FROM google/cloud-sdk:alpine` that `gcloud beta emulators pubsub start`

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •