This guide quickly explains how to getting started with Kogito Serverless Workflows in your local machine
To edit your workflows:
- Visual Studio Code with Red Hat Java Plugin installed
- Serverless Workflow Editor
To create the project skeleton, run:
quarkus create app \
-x=kogito-quarkus-serverless-workflow \
-x=quarkus-container-image-jib \
-x=quarkus-resteasy-jackson \
-x=quarkus-smallrye-openapi \
-x=kubernetes \
org.acme:my-first-ksw:1.0
The org.acme:my-first-ksw:1.0
is the group id, artifact id, and version of your project.
This command will create a Maven Quarkus project in the my-first-ksw
directory with all required Kogito dependencies.
Next, to make sure everything is working fine, try to compile the project with:
quarkus build
Go to the directory src/main/resources
and create a file named greetings.sw.yaml
.
You can play around and type the workflow definition by hand using the editor intellisense feature or copy and paste from the snnipet below:
---
id: greetings
version: '1.0'
name: Hello Person
start: InjectHello
functions:
- name: printOutput
type: custom
operation: sysout
states:
- name: InjectHello
type: inject
data:
message: 'Hello '
transition: PrintMessage
- name: PrintMessage
type: operation
actions:
- name: print
functionRef:
refName: printOutput
arguments:
message: "${ .message + .name }"
stateDataFilter:
output: "${ { message: (.message + .name) } }"
end: true
Then run quarkus dev
from the project's root to start the Quarkus console.
To interact with the application, we have a couple of options described in the sections below.
Point your browser to the http://localhost:8080/q/swagger-ui/ address.
You should see a POST endpoint definition for this workflow named Greetings
. Click on the POST entry and in the button "Try it".
Copy and paste the following content:
{
"workflowdata": {
"name" : "John"
}
}
Click on "Execute" and you should see a response similarly to this one:
{
"id": "c758eb9d-6242-4bda-a5f5-7f5d302943c0",
"workflowdata": {
"greeting": "Hello John",
}
}
You can use an one line curl
:
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"workflowdata" : {"name": "John"}}' http://localhost:8080/greetings
You can use the Quarkus CLI to build your image with the following command:
quarkus build \
-Dquarkus.container-image.build=true \
-Dquarkus.kubernetes.deployment-target=knative \
-Dquarkus.container-image.group=dev.local
After building the image, you can start the container running:
docker run --rm -it -p8080:8080 dev.local/my-first-ksw:1.0
You can then interact with the application the same way you did before in the previous sections.
Assuming you have installed Knative locally on your Minikube, run:
# Configure your docker env to push the images to the minikube registry first
eval $(minikube -p minikube docker-env --profile knative)
# rebuild the application to genereate the image in the right place
quarkus build \
-Dquarkus.container-image.build=true \
-Dquarkus.kubernetes.deployment-target=knative \
-Dquarkus.container-image.group=dev.local
# Install the app!
kubectl apply -f target/kubernetes/knative.yml
# You should see something like "service.serving.knative.dev/my-first-ksw created" in the terminal
Wait a couple of seconds and run kn service list
:
kn service list
NAME URL LATEST AGE CONDITIONS READY REASON
my-first-ksw http://my-first-ksw.default.127.0.0.1.sslip.io my-first-ksw-00001 12s 3 OK / 3 True
Access the application as you normally would.
Tip: Run
minikube tunnel -p knative
to be able to access the application from your terminal. Your admin password might be asked.