Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions functions/node/async-bindings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
apiVersion: core.openfunction.io/v1beta1
kind: Function
metadata:
name: sample-node-async-bindings
spec:
version: v2.0.0
image: your-docker-registry/image:tag
# imageCredentials:
# name: your-docker-registry-secret
# build:
# builder: openfunction/builder-node:v2-16.13
# env:
# FUNC_NAME: tryKnative
# srcRepo:
# url: https://github.com/OpenFunction/samples.git
# sourceSubPath: functions/node/src
# revision: main
# app port default to "8080"
# port: 8080
serving:
# default to knative
runtime: async
annotations:
# Dapr annotations: https://docs.dapr.io/reference/arguments-annotations-overview/
# default to "grpc"
dapr.io/app-protocol: http
# default to "info"
dapr.io/log-level: debug
# default to "true"
dapr.io/log-as-json: 'false'
template:
containers:
- name: function
imagePullPolicy: Always
params:
# default to FUNC_NAME value
FUNCTION_TARGET: tryAsync
DEBUG: common:*,ofn:*
inputs:
- name: mqtt-input
component: mqtt-in
outputs:
- name: mqtt-output
component: mqtt-out
operation: create
bindings:
# Dapr MQTT Binding: https://docs.dapr.io/reference/components-reference/supported-bindings/mqtt/
mqtt-in:
type: bindings.mqtt
version: v1
metadata:
- name: consumerID
value: '{uuid}'
- name: url
value: tcp://admin:public@emqx:1883
- name: topic
value: in
mqtt-out:
type: bindings.mqtt
version: v1
metadata:
- name: consumerID
value: '{uuid}'
- name: url
value: tcp://admin:public@emqx:1883
- name: topic
value: out
58 changes: 58 additions & 0 deletions functions/node/async-pubsub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
apiVersion: core.openfunction.io/v1beta1
kind: Function
metadata:
name: sample-node-async-pubsub
spec:
version: v2.0.0
image: your-docker-registry/image:tag
# imageCredentials:
# name: your-docker-registry-secret
# build:
# builder: openfunction/builder-node:v2-16.13
# env:
# FUNC_NAME: tryKnative
# srcRepo:
# url: https://github.com/OpenFunction/samples.git
# sourceSubPath: functions/node/src
# revision: main
# app port default to "8080"
# port: 8080
serving:
# default to knative
runtime: async
annotations:
# Dapr annotations: https://docs.dapr.io/reference/arguments-annotations-overview/
# default to "grpc"
dapr.io/app-protocol: http
# default to "info"
dapr.io/log-level: debug
# default to "true"
dapr.io/log-as-json: 'false'
template:
containers:
- name: function
imagePullPolicy: Always
params:
# default to FUNC_NAME value
FUNCTION_TARGET: tryAsync
DEBUG: common:*,ofn:*
inputs:
- name: mqtt-sub
component: mqtt-pubsub
topic: sub
outputs:
- name: mqtt-pub
component: mqtt-pubsub
topic: pub
pubsub:
# Dapr MQTT PubSub: https://docs.dapr.io/reference/components-reference/supported-pubsub/setup-mqtt/
mqtt-pubsub:
type: pubsub.mqtt
version: v1
metadata:
- name: consumerID
value: '{uuid}'
- name: url
value: tcp://admin:public@emqx:1883
- name: qos
value: 1
33 changes: 33 additions & 0 deletions functions/node/knative.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: core.openfunction.io/v1beta1
kind: Function
metadata:
name: sample-node-knative
spec:
version: v2.0.0
image: your-docker-registry/image:tag
# imageCredentials:
# name: your-docker-registry-secret
# build:
# builder: openfunction/builder-node:v2-16.13
# env:
# FUNC_NAME: tryKnative
# srcRepo:
# url: https://github.com/OpenFunction/samples.git
# sourceSubPath: functions/node/src
# revision: main
# app port default to "8080"
# port: 8080
serving:
runtime: knative
scaleOptions:
minReplicas: 0
maxReplicas: 2
template:
containers:
- name: function
imagePullPolicy: Always
params:
# default to "production"
NODE_ENV: dev
# Node.js debug wildcards
DEBUG: common:*,ofn:*
8 changes: 8 additions & 0 deletions functions/node/src/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const tryKnative = (req, res) => {
res.send(`Hello, ${req.query.u || 'World'}!`);
};

export const tryAsync = (ctx, data) => {
console.log('Data received: %o', data);
ctx.send(data);
};
9 changes: 9 additions & 0 deletions functions/node/src/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"main": "index.mjs",
"scripts": {
"start": "functions-framework --target=tryKnative"
},
"dependencies": {
"@openfunction/functions-framework": "^0.4.1"
}
}