Skip to content

Implements the envelope unwrap that is unsupported in the PubSub emulator

Notifications You must be signed in to change notification settings

extenda/pubsub-unwrapper

Repository files navigation

pubsub-unwrapper

Quality Gate Status Coverage Code Smells Duplicated Lines (%) WorkFlow

🔧 Local development environment

  • Node 18

🔩 Configuration

The service listens on local port 3000. Re-map the port to another suitable port if needed (via docker port mapping).

📔 Usage and Examples

PubSub example request:

{
  "subscription": "projects/test-project/subscriptions/test-subscription",
  "message": {
    "data": "c29tZSBkYXRhCg==", // "some data"
    "attributes": {
      "content-type": "text/plain",
      ...
    }
  }
}

The unwrapper works by inspecting the PubSub subscription field of the PubSub request body, and maps it against the subscription names configured as environmental variables. It will strip off the project id, replace hyphens with underscores and finally upper-case the subscription name;

projects/test-project/subscriptions/test-subscription becomes TEST_SUBSCRIPTION.
projects/test-project/subscriptions/reports-1 becomes REPORTS_1.

The data field of the request will be decoded and the contents sent as the new request body.

Content-Type

The content-type attribute must be set on the PubSub message, or an error will be raised. This mimics the PubSub unwrap functionality available in cloud.

Docker compose

To set up the unwrapper within a docker compose you could use the following configuration:

pubsub-unwrapper:
  image: extenda/pubsub-unwrapper
  environment:
    TEST_SUBSCRIPTION: http://localhost:8080/api/v1/endpoint-of-choice
    OTHER_SUBSCRIPTION: http://localhost:8080/api/v1/other-endpoint-of-choice
  ports:
    - "3000:3000"

Plain Docker

To run the service locally, you need a docker environment.
You will also be running a local PubSub emulator.

Build the docker image locally:

docker build . -t extenda/pubsub-unwrapper:latest

Pull the latest docker image:

docker pull extenda/pubsub-unwrapper:latest

Run the docker image:

docker run -p 3000:3000 -it --rm -e TEST_SUBSCRIPTION=http://localhost:8080/api/v1/endpoint-of-choice extenda/pubsub-unwrapper:latest

💁 Contribution

If you want to improve on the project, we appreciate feedback and contributions. But we ask of you to first follow or development environment guides.

About

Implements the envelope unwrap that is unsupported in the PubSub emulator

Resources

Stars

Watchers

Forks

Packages

No packages published