Invoking Knative services from Kogito Serverless Workflow
This document describes how to call Knative services using Kogito 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 Kogito Serverless Workflow service.
-
Your Kogito Serverless Workflow application is ready to use.
For more information about building the application container, see Building workflow images using Quarkus CLI. -
Minikube is installed
-
kubectl
command-line tool is installed. Otherwise, Minikube handles it. -
Knative CLI is installed.
For more information, see Install the Knative CLI. -
Knative workflow CLI is installed.
For more information see Serverless Workflow plug-in for Knative CLI. -
(Optional) Quarkus CLI is installed.
For more information, see Building Quarkus Apps with Quarkus command line interface (CLI). -
You have the custom-function-knative-service project deployed on Knative. For more information on how to deploy a Quarkus project to Knative, see the Quarkus Kubernetes extension documentation.
-
Add the
knative-serving
add-on dependency to your workflow project.<dependency> <groupId>org.kie.kogito</groupId> <artifactId>kogito-addons-quarkus-knative-serving</artifactId> </dependency>
-
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 http://custom-function-knative-service.default.10.109.169.193.sslip.io 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. -
Declare the Knative Kogito 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 Kogito 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 thecustom-function-knative-service
service.4 The resource path you want to access -
Invoke the declared function. In an
operation
state, add anaction
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 -
Deploy your workflow service to Knative. For more information on how to deploy a Kogito Serverless Workflow Kogito Serverless Workflow project to Knative, see the Deploying on Kubernetes.
-
Submit a request to the workflow service
curl -X 'POST' \ '<URL>/plainJsonKnativeFunction' \ (1) -H 'accept: */*' \ -H 'Content-Type: application/json' \ -d '{ "name": "Kogito" }'
1 Replace <URL>
with the URL of your deployed workflow serviceYou should see an output like (
id
will change):{"id":"87cf8275-782d-4e0b-a9be-a95f95c9c190","workflowdata":{"name":"Kogito","greeting":"Greetings from Serverless Workflow, Kogito"}}
Sending as CloudEvent
Knative functions support CloudEvent as the message protocol. Kogito Serverless Workflow can create and post CloudEvent messages in functionRef
. For more information see core/custom-functions-support.adoc#sending-cloudevents
Found an issue?
If you find an issue or any misleading information, please feel free to report it here. We really appreciate it!