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: README.md
+53-79Lines changed: 53 additions & 79 deletions
Original file line number
Diff line number
Diff line change
@@ -7,18 +7,19 @@
7
7
> This is OpenFunction's nodejs functions-framework forked from [GCP functions-framework-nodejs](https://github.com/GoogleCloudPlatform/functions-framework-nodejs)
8
8
9
9
An open source FaaS (Function as a Service) framework based on [Express](https://expressjs.com/)
10
-
for writing portable Node.js functions
10
+
and [Restana](https://github.com/BackendStack21/restana)for writing portable sync and async Node.js functions.
11
11
12
12
The Functions Framework lets you write lightweight functions that run in many
1. Open http://localhost:8080/ in your browser and see _Hello, World_.
80
+
1. Open <http://localhost:8080/> in your browser and see _Hello, World_.
81
81
82
82
### Quickstart:Set up a newproject
83
83
@@ -117,6 +117,7 @@ command-line arguments:
117
117
...
118
118
Serving function...
119
119
Function: helloWorld
120
+
Signature type: http
120
121
URL: http://localhost:8080/
121
122
```
122
123
@@ -129,10 +130,10 @@ command-line arguments:
129
130
130
131
### Quickstart: Build a Deployable Container
131
132
132
-
1. Install [Docker](https://store.docker.com/search?type=edition&offering=community) and the [`pack` tool](https://buildpacks.io/docs/install-pack/).
133
+
1. Install [Docker](https://store.docker.com/search?type=edition&offering=community) and the [pack](https://buildpacks.io/docs/install-pack/) tool.
134
+
135
+
2.Buildacontainerfromyourfunction using the [Cloud Native Buildpacks](https://buildpacks.io/):
133
136
134
-
1.Buildacontainerfromyourfunction using the Functions [buildpacks](https://github.com/GoogleCloudPlatform/buildpacks):
135
-
136
137
```sh
137
138
pack build \
138
139
--builder openfunction/builder-node:v2-16.13 \
@@ -141,44 +142,22 @@ command-line arguments:
141
142
my-first-function
142
143
```
143
144
144
-
1.Startthebuiltcontainer:
145
-
145
+
3.Startthebuiltfunction container:
146
+
146
147
```sh
147
-
docker run --rm -p 8080:8080 my-first-function
148
+
docker run --rm -p 8080:8080 -e NODE_ENV=dev my-first-function
148
149
# Output: Serving function...
149
150
```
150
151
151
-
1.Sendrequeststothisfunction using `curl` from another terminal window:
152
-
152
+
> NOTICE: `-e NODE_ENV=dev` is required to display "Serving function...", and you can also append `-e DEBUG=*` to display Express internal debug messages.
153
+
154
+
4. Send requests to this function using `curl` from another terminal window:
155
+
153
156
```sh
154
157
curl localhost:8080
155
158
# Output: Hello, World!
156
159
```
157
160
158
-
## Run your function on serverless platforms
159
-
160
-
### Google Cloud Functions
161
-
162
-
The
163
-
[Node.js 10 runtime on Google Cloud Functions](https://cloud.google.com/functions/docs/concepts/nodejs-10-runtime)
iscompletelyoptional:ifyoudon't add it to your `package.json`, it will be
166
-
installed automatically.
167
-
168
-
After you'vewrittenyourfunction, you can simply deploy it from your local
169
-
machine using the `gcloud` command-line tool.
170
-
[Check out the Cloud Functions quickstart](https://cloud.google.com/functions/docs/quickstart).
171
-
172
-
### CloudRun/CloudRunforAnthos
173
-
174
-
Afteryou've written your function, added the Functions Framework and updated your `start` script in `package.json`, deploy it to Cloud Run with `gcloud run deploy`. Check out the [Cloud Run quickstart for Node.js](https://cloud.google.com/run/docs/quickstarts/build-and-deploy/nodejs).
175
-
176
-
If you want even more control over the environment, you can [deploy to Cloud Run for Anthos](https://cloud.google.com/anthos/run/docs/quickstarts/prebuilt-deploy-gke). With Cloud Run for Anthos, you can run your function on a GKE cluster, which gives you additional control over the environment (including use of GPU-based instances, longer timeouts and more).
177
-
178
-
### Container environments based on Knative
179
-
180
-
Cloud Run and Cloud Run for Anthos both implement the [Knative Serving API](https://www.knative.dev/docs/). The Functions Framework is designed to be compatible with Knative environments. Just build and deploy your container to a Knative environment.
181
-
182
161
## Configure the Functions Framework
183
162
184
163
You can configure the Functions Framework using command-line flags or
@@ -201,34 +180,39 @@ For example:
201
180
}
202
181
```
203
182
204
-
## Enable Google Cloud Functions Events
183
+
## Run your function on Serverless platforms
205
184
206
-
The Functions Framework can unmarshall incoming
207
-
Google Cloud Functions [event](https://cloud.google.com/functions/docs/concepts/events-triggers#events) payloads to `data` and `context` objects.
208
-
These will be passed as arguments to your function when it receives a request.
209
-
Note that your function must use the `event`-style function signature:
185
+
### Container environments based on Knative
210
186
211
-
```js
212
-
exports.helloEvents = (data, context) => {
213
-
console.log(data);
214
-
console.log(context);
215
-
};
216
-
```
187
+
The Functions Framework is designed to be compatible with Knative environments. Build and deploy your container to a Knative environment.
Besides Knative function support, one notable feature of OpenFunction is embracing Dapr system, so far Dapr pub/sub and bindings have been support.
194
+
195
+
Dapr bindings allows you to trigger your applications or services with events coming in from external systems, or interface with external systems. OpenFunction [0.6.0 release](https://openfunction.dev/blog/2022/03/25/announcing-openfunction-0.6.0-faas-observability-http-trigger-and-more/) adds Dapr output bindings to its synchronous functions which enables HTTP triggers for asynchronous functions. For example, synchronous functions backed by the Knative runtime can now interact with middlewares defined by Dapr output binding or pub/sub, and an asynchronous function will be triggered by the events sent from the synchronous function.
196
+
197
+
Asynchronous function introduces Dapr pub/sub to provide a platform-agnostic API to send and receive messages. A typical use case is that you can leverage synchronous functions to receive an event in plain JSON or Cloud Events format, and then send the received event to a Dapr output binding or pub/sub component, most likely a message queue (e.g. Kafka, NATS Streaming, GCP PubSub, MQTT). Finally, the asynchronous function could be triggered from the message queue.
198
+
199
+
More details would be brought up to you in some quickstart samples, stay tuned.
200
+
201
+
### Google Cloud Functions
217
202
218
-
To enable automatic unmarshalling, set the function signature type to `event`
219
-
using a command-line flag or an environment variable. By default, the HTTP
220
-
signature will be used and automatic event unmarshalling will be disabled.
203
+
The [Node.js 10 runtime on Google Cloud Functions](https://cloud.google.com/functions/docs/concepts/nodejs-10-runtime) is based on the Functions Framework. On Cloud Functions, the Functions Framework is completely optional: if you don't add it to your `package.json`, it will be installed automatically.
221
204
222
-
For more details on this signature type, check out the Google Cloud Functions
After you've written your function, you can deploy it from your local machine using the `gcloud` command-line tool. [Check out the Cloud Functions quickstart](https://cloud.google.com/functions/docs/quickstart).
206
+
207
+
### Cloud Run / Cloud Run for Anthos
208
+
209
+
After you've written your function, added the Functions Framework and updated your `start` script in `package.json`, deploy it to Cloud Run with `gcloudrundeploy`. Check out the [Cloud Run quickstart for Node.js](https://cloud.google.com/run/docs/quickstarts/build-and-deploy/nodejs).
210
+
211
+
If you want even more control over the environment, you can [deploy to Cloud Run for Anthos](https://cloud.google.com/anthos/run/docs/quickstarts/prebuilt-deploy-gke). With Cloud Run for Anthos, you can run your function on a GKE cluster, which gives you additional control over the environment (including use of GPU-based instances, longer timeouts and more).
225
212
226
213
## Enable CloudEvents
227
214
228
-
The Functions Framework can unmarshall incoming
229
-
[CloudEvents](http://cloudevents.io) payloads to a `cloudevent` object.
230
-
It will be passed as an argument to your function when it receives a request.
231
-
Note that your function must use the `cloudevent`-style function signature:
215
+
The Functions Framework can unmarshall incoming [CloudEvents](http://cloudevents.io) payloads to a `cloudevent` object. It will be passed as an argument to your function when it receives a request. Note that your function must use the `cloudevent`-style function signature:
0 commit comments