- Node 18
The service listens on local port 3000. Re-map the port to another suitable port if needed (via docker port mapping).
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.
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.
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"
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
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.
- Commit messages must follow conventional commits
- SonarCloud quality gates must pass for all pull requests