Function Inputs and Outputs
Functions usually have inputs and outputs.
Function Inputs
For a sync function, the input is always the payload of the HTTP request.
For an async function, the input data comes from:
- Any Dapr Input Binding components of the Dapr Bindings Building Block
- Any Dapr Pub/sub brokers components of the Dapr Pub/sub Building Block
Function Outputs
For a sync function, the output can be sent through the HTTP response.
Both sync functions and async functions can send outputs to Dapr components including:
- Any Dapr Output Binding components of the Dapr Bindings Building Block
- Any Dapr Pub/sub brokers components of the Dapr Pub/sub Building Block
For example, here you can find an async function with a cron input binding and a Kafka output binding:
apiVersion: core.openfunction.io/v1beta1
kind: Function
metadata:
name: cron-input-kafka-output
spec:
...
serving:
...
runtime: "async"
inputs:
- name: cron
component: cron
outputs:
- name: sample
component: kafka-server
operation: "create"
bindings:
cron:
type: bindings.cron
version: v1
metadata:
- name: schedule
value: "@every 2s"
kafka-server:
type: bindings.kafka
version: v1
metadata:
- name: brokers
value: "kafka-server-kafka-brokers:9092"
- name: topics
value: "sample-topic"
- name: consumerGroup
value: "bindings-with-output"
- name: publishTopic
value: "sample-topic"
- name: authRequired
value: "false"
Here is another async function example that use a Kafka Pub/sub component as input.
apiVersion: core.openfunction.io/v1beta1
kind: Function
metadata:
name: autoscaling-subscriber
spec:
...
serving:
...
runtime: "async"
inputs:
- name: producer
component: kafka-server
topic: "sample-topic"
pubsub:
kafka-server:
type: pubsub.kafka
version: v1
metadata:
- name: brokers
value: "kafka-server-kafka-brokers:9092"
- name: authRequired
value: "false"
- name: allowedTopics
value: "sample-topic"
- name: consumerID
value: "autoscaling-subscriber"
Sync functions can also send output to Dapr output binding components or Pub/sub components, here is an example:
apiVersion: core.openfunction.io/v1beta1
kind: Function
metadata:
name: function-front
spec:
serving:
...
runtime: knative
outputs:
- name: target
component: kafka-server
operation: "create"
bindings:
kafka-server:
type: bindings.kafka
version: v1
metadata:
- name: brokers
value: "kafka-server-kafka-brokers:9092"
- name: authRequired
value: "false"
- name: publishTopic
value: "sample-topic"
- name: topics
value: "sample-topic"
- name: consumerGroup
value: "function-front"
当前内容版权归 OpenFunction 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 OpenFunction .