You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: module7-cloud-computing/r4.1-cloud-functions/README.md
+60Lines changed: 60 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,9 +25,69 @@ Cloud events are things that happen in your cloud environment. These might be th
25
25
26
26
Events occur whether or not you choose to respond to them. You create a response to an event with a trigger. A trigger is a declaration that you are interested in a certain event or set of events. Binding a function to a trigger allows you to capture and act on events.
27
27
28
+
## Types of Cloud Functions
29
+
30
+
There are two distinct types of Cloud Functions: HTTP functions and event-driven functions. Event-driven functions can be either background functions or CloudEvent functions, depending on which Cloud Functions runtime they are written for.
31
+
32
+
## HTTP Functions
33
+
34
+
You invoke HTTP functions from standard HTTP requests. These HTTP requests wait for the response and support handling of common HTTP request methods like GET, PUT, POST, DELETE and OPTIONS. When you use Cloud Functions, a TLS certificate is automatically provisioned for you, so all HTTP functions can be invoked via a secure connection.
35
+
36
+
```js
37
+
constescapeHtml=require("escape-html");
38
+
39
+
/**
40
+
* HTTP Cloud Function.
41
+
*
42
+
* @param{Object}req Cloud Function request context.
43
+
* More info: https://expressjs.com/en/api.html#req
44
+
* @param{Object}res Cloud Function response context.
45
+
* More info: https://expressjs.com/en/api.html#res
Before moving into background functions, we need to understand this term, Pub/Sub.
55
+
56
+
Pub/Sub, which stands for Publisher/Subscriber, allows services to communicate asynchronously, with latencies on the order of 100 milliseconds.
57
+
58
+
Pub/Sub is used for streaming analytics and data integration pipelines to ingest and distribute data. It is equally effective as messaging-oriented middleware for service integration or as a queue to parallelize tasks.
59
+
60
+
<b>What is background functions?</b>
61
+
62
+
A background function is one type of event-driven function.
63
+
You use background functions when you want to have your Cloud Function invoked indirectly in response to an event, such as a message on a Pub/Sub topic, a change in a Cloud Storage bucket, or a Firebase event.
64
+
65
+
Pub/Sub example
66
+
67
+
This example shows a Cloud Function triggered by Pub/Sub events. Every time a message is published to a Pub/Sub topic, the function is invoked, and a greeting using data derived from the message is written to the log
68
+
69
+
```js
70
+
/**
71
+
* Background Cloud Function to be triggered by Pub/Sub.
72
+
* This function is exported by index.js, and executed when
0 commit comments