This example contains a simple workflow service that illustrate compensation handling. The service is described using JSON format as defined in the CNCF Serverless Workflow specification. This is simple workflow that expects a boolean shouldCompensate
to indicate if compensation segment (which is composed by two inject states
) should be executed or not. The process result is a boolean field compensated
which value should match shouldCompensate
.
You will need:
When using native image compilation, you will also need:
mvn clean package quarkus:dev
mvn clean package java -jar target/quarkus-app/quarkus-run.jar
or on windows
mvn clean package java -jar target\quarkus-app\quarkus-run.jar
Note that this requires GRAALVM_HOME to point to a valid GraalVM installation
mvn clean package -Pnative
To run the generated native executable, generated in target/
, execute
./target/serverless-workflow-compensation-quarkus-{version}-runner
The service based on the JSON workflow definition can be access by sending a request to http://localhost:8080/compensation' with following content
{ "shouldCompensate": true }
Complete curl command can be found below:
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"shouldCompensate": true}' http://localhost:8080/compensation
Should return something like this (“id” will change)
{ "id": "b1e8ce8d-2fc5-4d39-b3b3-6f7dddbb1515", "workflowdata": { "shouldCompensate": true, "compensated": "true" "compensating_more": "Real Betis Balompie" } }
If you would like to check output when there is no compensation
{ "shouldCompensate": false }
Complete curl command can be found below:
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"shouldCompensate": false}' http://localhost:8080/compensation
Should return something like this (“id” will change)
{ "id": "c106c3f9-8a21-44c0-83df-1191b6a04672", "workflowdata": { "shouldCompensate": false, "compensated": false } }