This example contains a simple workflow service that demonstrates how to use Data Index persistence addon as part of the Kogito runtime. The service is described using JSON format as defined in the CNCF Serverless Workflow specification.
This example also requires persistence with a PostgreSQL server.
Optionally and for convenience, a docker-compose configuration file is provided in the path docker-compose/, where you can just run the command from there:
./startServices.sh
The configuration for setting up the connection can be found in applications.properties file, which follows the Quarkus JDBC settings, for more information please check JDBC Configuration Reference.
In this way a container for PostgreSQL will be started on port 5432.
You will need:
When using native image compilation, you will also need: - GraalVM 22.2+ installed - Environment variable GRAALVM_HOME set accordingly - GraalVM native image needs as well native-image extension: https://www.graalvm.org/reference-manual/native-image/ - Note that GraalVM native image compilation typically requires other packages (glibc-devel, zlib-devel and gcc) to be installed too, please refer to GraalVM installation documentation for more details.
NOTE: Quarkus provides a way of creating a native Linux executable without GraalVM installed, leveraging a container runtime such as Docker or Podman. More details in https://quarkus.io/guides/building-native-image#container-runtime
mvn clean package quarkus:dev
NOTE: Data Index graphql UI will be available in http://localhost:8180/graphiql/
You should start all the services before you execute any of the Data Index example. To do that please execute:
mvn clean package -Pcontainer
For Linux and MacOS:
docker-compose up
cd docker-compose && ./startServices.sh
TIP: If you get a permission denied
error while creating the postgresql container, consider using SELinux context. Update the following line:
- ./sql:/docker-entrypoint-initdb.d
to
- ./sql:/docker-entrypoint-initdb.d:Z
Once all services bootstrap, the following ports will be assigned on your local machine:
NOTE: This step requires the project to be compiled, please consider running a
mvn clean package -Dcontainer
command on the project root before running thedocker-compose up
for the first time or any time you modify the project.
Once started you can simply stop all services by executing the docker-compose stop
.
All created containers can be removed by executing the docker-compose rm
.
The service based on the JSON workflow definition can be access by sending a request to http://localhost:8080/greet' with following content
{ "name": "John", "language": "English" }
Complete curl command can be found below:
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"name": "John", "language": "English"}' http://localhost:8080/greet
Log after curl executed:
{"id":"541a5363-1667-4f6d-a8b4-1299eba81eac","workflowdata":{"name":"John","language":"English","greeting":"Hello from JSON Workflow, "}}
In Quarkus you should see the log message printed:
Hello from JSON Workflow, John
If you would like to greet the person in Spanish, we need to pass the following data on workflow start:
{ "name": "John", "language": "Spanish" }
Complete curl command can be found below:
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"name": "John", "language": "Spanish"}' http://localhost:8080/greet
In Quarkus you should now see the log message printed:
Saludos desde JSON Workflow, John
Then we can verify that the data has been properly indexed accessing to http://localhost:8180/graphiql/ and executing the query:
{ProcessInstances { id variables }}
getting as a result:
{ "data": { "ProcessInstances": [ { "id": "0b95e8a1-b52f-48cf-b7d0-38fa3087d467", "variables": { "workflowdata": { "name": "John", "greeting": "Hello from JSON Workflow, ", "language": "English" } } }, { "id": "141f7350-7802-4abc-985c-333caf1068f9", "variables": { "workflowdata": { "name": "John", "greeting": "Saludos desde JSON Workflow, ", "language": "Spanish" } } } ] } }
Or by command line, executing the complete curl command can be found below:
curl -H "Content-Type: application/json" -H "Accept: application/json" -X POST --data '{"query" : "{ProcessInstances {id variables}}" }' http://localhost:8180/graphql
getting
{"data":{"ProcessInstances":[{"id":"0b95e8a1-b52f-48cf-b7d0-38fa3087d467","variables":{"workflowdata":{"name":"John","greeting":"Hello from JSON Workflow, ","language":"English"}}},{"id":"141f7350-7802-4abc-985c-333caf1068f9","variables":{"workflowdata":{"name":"John","greeting":"Saludos desde JSON Workflow, ","language":"Spanish"}}}]}}