This example aims to port an example of AWS Step functions into the Knative/Serverless Workflow platform.
- Ko installed
- Java SDK installed
- Maven installed
- Quarkus CLI
- Knative quickstart plugin
- Kind
- PostgreSQL
To edit your workflows:
- Visual Studio Code with Red Hat Java Plugin installed
- Serverless Workflow Editor
Skip this step if you have already access to a Kubernetes with Knative Serving.
Create a Kind cluster and install Knative Serving by using this command:
kn quickstart kind --install-serving
ko supports loading images directly to Kind local registry:
export KO_DOCKER_REPO=kind.local
Below is the name of the kind cluster created by kn quickstart
export KIND_CLUSTER_NAME=knative
The commerce application stores orders and inventories in postgreSQL.
Install kubegres:
kubectl apply -f https://raw.githubusercontent.com/reactive-tech/kubegres/v1.15/kubegres.yaml
kubectl wait deployment -n kubegres-system kubegres-controller-manager --for condition=Available=True --timeout=90s
kubectl apply -f config/infra/postgres
Use ko apply
to apply the YAML config for all functions:
ko apply -f config
To create the project skeleton, run:
kn workflow create --name e-commerce-ksw
This command will create a Maven Quarkus project in the e-commerce-ksw
directory with all required Kogito dependencies.
rm -rf e-commerce-ksw/src/main/resources/* && cp config/sw/* e-commerce-ksw/src/main/resources
Navigate to your project's directory. For this example:
cd e-commerce-ksw
You can use the Serverless Workflow plug-in for the Knative CLI to build your image with the following command:
kn workflow build --image dev.local/e-commerce-ksw:1.0
Load the produced container image into Kind:
kind load docker-image dev.local/e-commerce-ksw:1.0 --name=knative
Then deploy the workflow as a Knative application:
kn service create -f target/kubernetes/knative.yml
You should see something like "service.serving.knative.dev/e-commerce-ksw created" in the terminal
Check the service is ready:
kn service list
Expected output:
NAME URL LATEST AGE CONDITIONS READY REASON
e-commerce-ksw http://e-commerce-ksw.default.127.0.0.1.sslip.io e-commerce-ksw-00001 12s 3 OK / 3 True
To interact with the application, you can call the service via command line
curl -v -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"workflowdata" : {"order_id":"8dee2","order_info":{"order_date":"2022-01-01T02:30:50Z","customer_id":"id001","order_status":"fillIn","items": [{"item_id":"itemID456","qty":1,"description":"Pencil","unit_price":2.5},{"item_id":"itemID789","qty":1,"description":"Paper","unit_price":4}],"payment":{"merchant_id":"merchantID1234","payment_amount":6.5,"transaction_id":"54c512","transaction_date":"2022-01-01T02:30:50Z","order_id":"8dee2","payment_type":"creditcard"},"inventory":{"transaction_id":"54c512","transaction_date":"2022-01-01T02:30:50Z","order_id":"8dee2","items":["Pencil","Paper"],"transaction_type":"online"}}}}' http://e-commerce-ksw.default.127.0.0.1.sslip.io/commerce