Giter Club home page Giter Club logo

pubsub-emulator's Introduction



An easy-to-use CLI app for effortlessly managing your local Pub/Sub environment
and automatically syncing it with your Google Cloud Pub/Sub configuration.



Motivation

The inspiration for pubsub-emulator stemmed from the challenges faced when integrating Pub/Sub into various projects. A key obstacle was the lack of an effective method to replicate the Pub/Sub setup locally. Although Google Cloud's beta Pub/Sub emulator was a step in the right direction, it started as an empty slate each time, missing the crucial topics and subscriptions needed for communication. To address this gap, this project was developed with three core functionalities:

  1. Import topics and subscriptions from a GCP project to a local Pub/Sub environment.
  2. Automatically translate production push endpoints into local URLs.
  3. Provide a simple CRUD interface for managing topics and subscriptions locally.

Prerequisites


Configuring Service Mappings

1. Create the JSON File

Start by creating a new JSON file in your project directory.
You can name it service-mappings.json (or any name you prefer).

2. Define the Mappings

In this file, you'll define a series of key-value pairs where each key is the URL of a cloud service, and the corresponding value is the localhost port to which it should be mapped. For example, if your service URL is https://some-service-k4caugryxh-cha.run.app and the corresponding local URL is localhost:8080, then your service-mappings.json should look like this:

{
  "some-service-k4caugryxh-cha.run.app": 8080
}

3. Set the Environment Variable

Set an environment variable that points to the location of your JSON configuration file.

echo 'SERVICE_MAPPINGS_PATH=service-mappings.json' >> .env

Setup

Ensure that all necessary dependencies are installed.

poetry install

Set the PROJECT_ID environment variable to your Google Cloud project ID.

echo 'PROJECT_ID=my-project' >> .env

Start the Pub/Sub emulator by executing this command in a new terminal tab or window. 2

gcloud beta emulators pubsub start

Set up the required environment variables for the Pub/Sub emulator connection to work. 3

$(gcloud beta emulators pubsub env-init)

Usage

Importing Cloud Pub/Sub Configuration

Synchronize your cloud configuration with the local emulator to ensure that your local environment mirrors the cloud setup with the appropriate local URLs.

make sync

Running CLI Commands

Execute commands in pubsub-emulator through Poetry using the following syntax:

poetry run python pubsub_emulator <COMMAND>

Replace <COMMAND> with the specific command you wish to execute.
This method ensures that your commands run within the project's virtual environment.

Accessing Help

To view a list of all available commands and their options in pubsub-emulator, you can use the --help option.

poetry run python pubsub_emulator --help
poetry run python pubsub_emulator <COMMAND> --help

Reference Subscriptions Structure

When creating or updating a subscription with pubsub-emulator, it's necessary to pass a request object in JSON string format. To ensure you're using the correct structure for this request, refer to the latest subscription structure definitions in Google's official Pub/Sub Library.


License

This project is licensed under the CC BY-NC 4.0 DEED (Attribution-NonCommercial 4.0 International), which essentially means you are free to share and adapt the material in this repository, provided you give appropriate credit, indicate if changes were made, and, most importantly, do not use it for commercial purposes.


Contact

Feel free to reach out through one of the following channels:



Footnotes

  1. I recommend using Pyenv for managing Python versions

  2. Since this command can't be executed in the background

  3. For more details about this command visit the official Pub/Sub emulator guide

pubsub-emulator's People

Contributors

cnsfeir avatar

Stargazers

Francisco Besoain avatar Joaquín Castaños avatar Benjamin avatar

Watchers

 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.