Giter Site home page Giter Site logo

google-pub-sub's Introduction

ipm package: google-pub-sub

Overview

This package is a template system to connect with Google Cloud using REST subscribe to topics. It uses the Pull Subscription approach for subscription.

Browse ipm Packages

Setup

Gcloud Setup Summary
Create Gcloud account
Create a project in gcloud
Create a topic(optional)
Create a subscription for the desired topic
Create a service account
  1. Setup on Gcloud Detailed: Following steps are assuming user already has an account and has access to Gcloud IoT Console.
    1. If you already have a project created and also have a topic which you wish to subscribe to, then directly go to step 3.
    2. Perform the Iot core quickstart: This will involve creating a device, device registry & a certificate, creating a topic and a subscription.
    3. Now that you have a topic in a project to subscribe to, create a pull subscription if you don't already have one. Follow this link to create a pull subscription.
    4. We use a service account to perform the pull subscription over HTTP REST. Follow the steps here to create a service account on google and generate a key. This key is used to generate access token that is used to perform the pull and acknowledgement. Things to note here are:
      1. default maximum validity for access token is 3600 seconds.
      2. The additional steps to increase the default maximum validity for access token are here
  2. Setup on ClearBlade:
    1. Get the Desired Credentials and update the Google IoT Configuration Library. The credentials include PROJECT_ID, MAX_MESSAGES_TO_PULL, SUBSCRIPTION_NAME, SUBSCRIPTION_SERVICE_ACCOUNT_PRIVATE_KEY from the above Gcloud checklist summary.
    2. Restart the pullSubscription service once the GoogleIoTConfig Library is updated.
    3. Update the pullTimer and updateAccessTokenTimer based on your use-case.

Usage

The accessTokenManager service listens on a timer to fetch a new access token. The reason we do that is the expiry time of an access token is limited, a maximum of 3600s. This service updates the AccessToken in a shared cache, which is used by the pullSubscription service to make a pull to the subscription.

Note: One can manually update the access token in the shared cache, by simply invoking the accessTokenManager service.

Assets

Code Services

  • accessTokenManager -- a service that uses the private for a service account along with other credentials in the GoogleIoTConfig library to gain the access token and update the shared cache with the latest access_token. This service runs of a timer, updateAccessTokenTimer. The frequency of execution of this timer should be less than 3600s, since the access_token has a maximum expiry time of 3600s.
  • pullSubscription -- a stream service which regularly pulls on a topic. The determine of pull's is defined by the pullTimer. If the pullTimer fires every 20 seconds, then the service makes a pull to the topic on google every 20 seconds. It reads the accessToken from the shared cache which is updated regularly by the accessTokenManager service.

Code Libraries

GoogleIoTConfig -- a configuration library, which holds constants specific to Google IoT.

Timers

The timers can be updated based on your use-case:

  • pullTimer - this timer defines the frequency of your pull.
  • updateAccessTokenTimer - this timer defines the frequency at which the access token gets updated.

Shared Cache

AccessTokenCache - this cache stores the latest and active access_token. The expiry time for this cache is set to 3600s.

google-pub-sub's People

Contributors

clarkbynum avatar clearbladeplatform avatar

Watchers

 avatar  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.