Skip to content

docs: add quickstart for Pub/Sub emulator #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,31 @@ def function(request):
This function will catch the `ZeroDivisionError` and return a different
response instead.

### Quickstart: With Pub/Sub Emulator

1. Start Functions Frameworks in local development server listening on port 8082:
```sh
functions-framework --target=hello --debug --port=8082
```
1. Start Pub/Sub Emulator.
```sh
export PUBSUB_PROJECT_ID=abc
gcloud beta emulators pubsub start \
--project=$PUBSUB_PROJECT_ID \
--host-port=localhost:8080
```
1. Create a Pub/Sub topic and attach a push subscription to the topic, using `http://localhost:8082` as its push endpoint. Publish some messages to the topic. Observe your function getting triggered by Pub/Sub messages.
```sh
export TOPIC_ID_=may
export PUSH_SUBSCRIPTION_ID=five
$(gcloud beta emulators pubsub env-init)
git clone https://github.com/googleapis/python-pubsub.git
cd python-pubsub/samples/snippets/
python publisher.py $PUBSUB_PROJECT_ID create $TOPIC_ID
python subscriber.py $PUBSUB_PROJECT_ID create $TOPIC_ID $PUSH_SUBSCRIPTION_ID http://localhost:8082
python publisher.py $PUBSUB_PROJECT_ID publish $TOPIC_ID
```

### Quickstart: Build a Deployable Container

1. Install [Docker](https://store.docker.com/search?type=edition&offering=community) and the [`pack` tool](https://buildpacks.io/docs/install-pack/).
Expand Down