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:

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:

For example, here you can find an async function with a cron input binding and a Kafka output binding:

  1. apiVersion: core.openfunction.io/v1beta1
  2. kind: Function
  3. metadata:
  4. name: cron-input-kafka-output
  5. spec:
  6. ...
  7. serving:
  8. ...
  9. runtime: "async"
  10. inputs:
  11. - name: cron
  12. component: cron
  13. outputs:
  14. - name: sample
  15. component: kafka-server
  16. operation: "create"
  17. bindings:
  18. cron:
  19. type: bindings.cron
  20. version: v1
  21. metadata:
  22. - name: schedule
  23. value: "@every 2s"
  24. kafka-server:
  25. type: bindings.kafka
  26. version: v1
  27. metadata:
  28. - name: brokers
  29. value: "kafka-server-kafka-brokers:9092"
  30. - name: topics
  31. value: "sample-topic"
  32. - name: consumerGroup
  33. value: "bindings-with-output"
  34. - name: publishTopic
  35. value: "sample-topic"
  36. - name: authRequired
  37. value: "false"

Here is another async function example that use a Kafka Pub/sub component as input.

  1. apiVersion: core.openfunction.io/v1beta1
  2. kind: Function
  3. metadata:
  4. name: autoscaling-subscriber
  5. spec:
  6. ...
  7. serving:
  8. ...
  9. runtime: "async"
  10. inputs:
  11. - name: producer
  12. component: kafka-server
  13. topic: "sample-topic"
  14. pubsub:
  15. kafka-server:
  16. type: pubsub.kafka
  17. version: v1
  18. metadata:
  19. - name: brokers
  20. value: "kafka-server-kafka-brokers:9092"
  21. - name: authRequired
  22. value: "false"
  23. - name: allowedTopics
  24. value: "sample-topic"
  25. - name: consumerID
  26. value: "autoscaling-subscriber"

Sync functions can also send output to Dapr output binding components or Pub/sub components, here is an example:

  1. apiVersion: core.openfunction.io/v1beta1
  2. kind: Function
  3. metadata:
  4. name: function-front
  5. spec:
  6. serving:
  7. ...
  8. runtime: knative
  9. outputs:
  10. - name: target
  11. component: kafka-server
  12. operation: "create"
  13. bindings:
  14. kafka-server:
  15. type: bindings.kafka
  16. version: v1
  17. metadata:
  18. - name: brokers
  19. value: "kafka-server-kafka-brokers:9092"
  20. - name: authRequired
  21. value: "false"
  22. - name: publishTopic
  23. value: "sample-topic"
  24. - name: topics
  25. value: "sample-topic"
  26. - name: consumerGroup
  27. value: "function-front"

Last modified June 19, 2022: Rename Function_IO.md to function_io.md (e346e90)