Invoking Knative services from Serverless Workflow

This document describes how to call Knative services using Serverless Workflow custom functions. The procedure described in this document is based on the serverless-workflow-custom-function-knative example application.

For more details about the Knative custom function, see Custom functions for your Serverless Workflow service.

  1. Add the knative-serving add-on dependency to your workflow project.

  2. Discover the name of the Knative service that your workflow will invoke. In a terminal window, run the following command:

    kn service list

    You should see an output like:

    NAME                              URL                                                                      LATEST                                  AGE     CONDITIONS   READY   REASON
    custom-function-knative-service   custom-function-knative-service-00001   3h16m   3 OK / 3     True

    Save the Knative service name (custom-function-knative-service) to use it in the next step.

  3. Declare the Knative Serverless Workflow custom function. In the functions section of your workflow, add the following:

      "name": "greet", (1)
      "type": "custom", (2)
      "operation": "knative:custom-function-knative-service", (3)
      "metadata": {
        "path": "/function" (4)
    1 The name of the Serverless Workflow function
    2 Indicates that this function is a custom one
    3 Indicates that your custom function is of type knative and it will invoke the custom-function-knative-service service.
    4 The resource path you want to access
  4. Invoke the declared function. In an operation state, add an action that references the function you declared in the previous step like the following:

    "actions": [
        "functionRef": {
          "refName": "greet", (1)
          "arguments": { (2)
            "name": ".name"
    1 Function’s name
    2 The payload that should be sent in the request
  5. Deploy your workflow service to Knative. For more information on how to deploy a Kogito Serverless Workflow project to Knative, see the Deploying on Kubernetes.

  6. Submit a request to the workflow service

    curl -X 'POST' \
      '<URL>/knativeFunction' \ (1)
      -H 'accept: */*' \
      -H 'Content-Type: application/json' \
      -d '{ "name": "Kogito" }'
    1 Replace <URL> with the URL of your deployed workflow service

    You should see an output like (id will change):

    {"id":"87cf8275-782d-4e0b-a9be-a95f95c9c190","workflowdata":{"name":"Kogito","greeting":"Greetings from Serverless Workflow, Kogito"}}

Found an issue?

If you find an issue or any misleading information, please feel free to report it here. We really appreciate it!