cloud ☁️ function, pub/sub and scheduler

cloud ☁️ function, pub/sub and scheduler

introduction

cloud function

  • it's a server-less function running on the GCP, which means you don't have to manage VMs or docker containers
    • use cases 👇
    • log analysis, trigger the cloud function when ERROR occurs
    • automated backup, taking a backup of files at a regular interval
  • refer this for more info

pub/sub

  • GCP pub/sub enables reliable async communication between microservices/applications with the concept of topic, publisher, subscriber and message
  • for more info refer gcp documentation

scheduler

  • schedule jobs at regular/defined intervals(cron jobs)
  • refer this for more

Examples

1. take backup at a regular interval

QrMenu (2).png

steps

  • create a topic in pub/sub

image.png

  • go to cloud build & enable services as shown below

d55df289-9813-4486-89e3-bd1069812f0e.png

  • create a GCP cloud function & attach a service account to it
  • in the trigger section choose Pub/Sub triggers and the topic which you have recently created
  • now click next & choose python3.8 as a coding language, clear all the code present inside the function & print("hello world") instead
  • now go to the pub/sub select the topic & send a message manually
  • now navigate back to the function, and switch to the logs panel, here you should be able to see "hello world" message
  • go to the scheduler service & create a new job, in frequency write * 5 times, which means it'll send a message on the interval of 1 min,in target-type select pub/sub, select your topic & write your message unnamed.png
  • now our function will be executed after every minute
  • you can write code to read/write files from cloud filestore with python sdk or api, make sure service account have sufficient permission

2. Integration with third-party services(github) and APIs

3. Serverless mobile back ends

references

it's over🎉, thanks for reading