Giter VIP home page Giter VIP logo

gcloud-pubsub-emulator's Introduction

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.

gcloud-pubsub-emulator's People

Contributors

iki avatar keirsweeney avatar marcelcorso avatar prep avatar thanosp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.