tree: 7284d392a3a06921ab091a7a667313b6d9e54f28 [path history] [tgz]
  1. src/
  2. pom.xml
  3. README.md
serverless-workflow-examples/serverless-workflow-qas-service-showcase/query-answer-service/README.md

Kogito Serverless Workflow - Query Answer Service Example

Description

This project contains a simple serverless workflow and some auxiliary resources that implement the Query and Answer Service described in the serverless-workflow-qas-service-showcase/README.md. Please read it before to continue.

The service is described using JSON format as defined in the CNCF Serverless Workflow specification.

Infrastructure requirements

Kafka

This quickstart requires an Apache Kafka to be available and, by default, expects it to be on the default port and localhost.

  • Install and Startup Kafka Server / Zookeeper

https://kafka.apache.org/quickstart

The topic “query_response_events” is used to publish and consume the events.

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:

docker-compose up

In this way, a container for Kafka will be started on port 9092.

PostgreSQL

Alternatively, you can run this example using persistence with a PostgreSQL server.

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.

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:

docker-compose up

In this way, a container for PostgreSQL will be started on port 5432.

Installing and Running

Prerequisites

You will need:

  • Java 17+ installed
  • Environment variable JAVA_HOME set accordingly
  • Maven 3.9.6+ installed

When using native image compilation, you will also need:

  • GraalVm 19.3.1+ installed
  • Environment variable GRAALVM_HOME set accordingly
  • Note that GraalVM native image compilation typically requires other packages (glibc-devel, zlib-devel and gcc) to be installed too. You also need ‘native-image’ installed in GraalVM (using ‘gu install native-image’). Please refer to GraalVM installation documentation for more details.

Compile and Run in Local Dev Mode

mvn clean package quarkus:dev

Compile and Run in JVM mode

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

Compile and Run in JVM mode using PostgreSQL persistence

To enable persistence, please append -Ppersistence to your Maven command. That will ensure the correct dependencies are in place, and automatically set the required properties to connect with the PostgreSQL instance from the provided docker compose.

mvn clean package -Ppersistence 

Compile and Run using Local Native Image

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/query-answer-service-{version}-runner

Submit a request

The service based on the JSON workflow definition can be accessed by sending requests to the http://localhost:8080/qaservice url.

Use the following curl command to list all the active serverless workflow instances:

curl -X 'GET' 'http://localhost:8080/qaservice' -H 'accept: application/json'

Use the following curl command to create a new serverless workflow instance:

curl -X 'POST' 'http://localhost:8080/qaservice' -H 'accept: application/json' -H 'Content-Type: application/json' \
-d '{ "query" : "the text for my query" }'

Use the following curl command to list the knowledge database:

curl -X 'GET' 'http://localhost:8080/queries' -H 'accept: application/json'

Swagger UI

The swagger is also available in the following url: http://localhost:8080/q/swagger-ui