This example contains a simple workflow service that consumes events over HTTP. The service is described using JSON format as defined in the CNCF Serverless Workflow specification. It's a simple workflow that, after starting, waits for an event to be published over HTTP. Then the workflow prints the event content to the console when the event is received.
To go further on using HTTP with Reactive Messaging, take a look at this article.
This is the infrastructure required to integrate with Knative Eventing.
Knative Eventing uses standard HTTP POST requests to send and receive events between event producers and sinks. These events conform to the CloudEvents specifications, which enables creating, parsing, sending, and receiving events in any programming language.
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 started by sending a request to http://localhost:8080/start' with following content
{ "message": "Hello" }
Complete curl command can be found below:
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"message": "Hello"}' http://localhost:8080/start
Should return something like this (“id” will change):
{ "id":"f9a75f77-7269-4b18-93cd-2955e3406cd4", "workflowdata":{ "message":"Hello" }, "waitForEvent_9":null }
You should see the message printed to the console in Quarkus log.
[ "Hello" ]
At this point, your workflow is waiting for an event to be published over HTTP. Send the following event: (You should use in “kogitoprocrefid” field the id returned by the previous request)
{ "specversion":"1.0", "source":"", "type":"move", "time":"2022-01-06T15:35:29.967831-03:00", "kogitoprocrefid":"f9a75f77-7269-4b18-93cd-2955e3406cd4", "data":{ "move":"This has been injected by the event" } }
Complete curl command can be found below:
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"specversion":"1.0","id":"e4604756-f58e-440e-9619-484b92408308","source":"","type":"move","time":"2022-01-06T15:35:29.967831-03:00","kogitoprocrefid":"f9a75f77-7269-4b18-93cd-2955e3406cd4","data":{"move":"This has been injected by the event"}}' http://localhost:8080/
The workflow will consume the event and print the message you sent to the console.
[ "Hello", "This has been injected by the event" ]