Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.
/ SPCPM Public archive

Solar Powered City Pollution Monitor

Notifications You must be signed in to change notification settings

Nyceane/SPCPM

Repository files navigation

Node.js Cloud Pub/Sub sample for Google App Engine

This sample shows how to send and receive messages using Google Cloud Pub/Sub on Google App Engine standard environment and flexible environment.

Setup

Before you can run or deploy the sample, you will need to do the following:

  1. Enable the Cloud Pub/Sub API in the Google Developers Console.

  2. Create a topic and subscription.

     gcloud beta pubsub topics create <your-topic-name>
     gcloud beta pubsub subscriptions create <your-subscription-name> \
       --topic <your-topic-name> \
       --push-endpoint \
         https://<your-project-id>.appspot.com/pubsub/push?token=<your-verification-token> \
       --ack-deadline 30
    
  3. Update the environment variables in app.standard.yaml or app.flexible.yaml (depending on your App Engine environment).

Running locally

Refer to the appengine/README.md file for instructions on running and deploying.

When running locally, you can use the Google Cloud SDK to provide authentication to use Google Cloud APIs:

gcloud init

Then set environment variables before starting your application:

export PUBSUB_VERIFICATION_TOKEN=<your-verification-token>
export PUBSUB_TOPIC=<your-topic-name>
npm start

Simulating push notifications

The application can send messages locally, but it is not able to receive push messages locally. You can, however, simulate a push message by making an HTTP request to the local push notification endpoint. There is an included sample_message.json. You can use curl or httpie to POST this:

curl -H "Content-Type: application/json" -i --data @sample_message.json ":8080/pubsub/push?token=<your-verification-token>"

Or

http POST ":8080/pubsub/push?token=<your-verification-token>" < sample_message.json

Response:

HTTP/1.1 200 OK
Connection: keep-alive
Date: Mon, 31 Aug 2015 22:19:50 GMT
Transfer-Encoding: chunked
X-Powered-By: Express

After the request completes, you can refresh localhost:8080 and see the message in the list of received messages.

About

Solar Powered City Pollution Monitor

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published