This example contains four simple greeting workflow services that use gRPC and one workflow for the purpose of error testing. The services are described using a JSON format as defined in the CNCF Serverless Workflow specification.
The workflows are:
Each workflow expects a different JSON input based on the gRPC method called. (see details in the Submit a request section).
Each flow then prints out the greeting(s) to the console.
The languages supported currently are English and Spanish. In case a supported language is not recognized, English is chosen as a default.
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/sw-quarkus-greeting-{version}-runner
The service based on the JSON workflow definition can be accessed by sending a request to http://localhost:8080/jsongreet with the 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/jsongreet
Log after curl executed:
{"id":"541a5363-1667-4f6d-a8b4-1299eba81eac","workflowdata":{"name":"John","language":"English","message":"Hello from gRPC service 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/jsongreet
The service based on the JSON workflow definition can be accessed by sending a request to http://localhost:8080/jsongreetserverstream with the following content
{ "name": "John" }
Language parameter is not needed as the gRPC server will send greetings in all languages at all times.
Complete curl command can be found below:
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"name": "John"}' http://localhost:8080/jsongreetserverstream
Log after curl executed:
{"id":"665911c5-36ee-40b7-93dd-a2328f969c73","workflowdata":{"name":"John","response":[{"message":"Hello from gRPC service John"},{"message":"Saludos desde gRPC service John"}]}}
Notice that greetings in both languages were received.
The service based on the JSON workflow definition can be accessed by sending a request to http://localhost:8080/jsongreetclientstream with the following content
{ "helloRequests": [ { "name": "Javierito", "language": "Spanish" }, { "name": "John", "language": "English" }, { "name": "Jan", "language": "Czech" } ] }
Complete curl command can be found below:
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"helloRequests" : [{"name" : "Javierito", "language":"Spanish"}, {"name" : "John", "language":"English"}, {"name" : "Jan", "language":"Czech"} ]}' http://localhost:8080/jsongreetclientstream
Log after curl executed:
{"id":"abece3f9-0797-4c10-a1f5-8f3929724689","workflowdata":{"helloRequests":[{"name":"Javierito","language":"Spanish"},{"name":"John","language":"English"},{"name":"Jan","language":"Czech"}],"message":"Saludos desde gRPC service Javierito\nHello from gRPC service John\nHello from gRPC service Jan"}}
Notice that one greeting with respective names and languages was received.
The service based on the JSON workflow definition can be accessed by sending a request to http://localhost:8080/jsongreetbidistream with the following content
{ "helloRequests": [ { "name": "Javierito", "language": "Spanish" }, { "name": "John", "language": "English" }, { "name": "Jan", "language": "Czech" } ] }
Complete curl command can be found below:
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"helloRequests" : [{"name" : "Javierito", "language":"Spanish"}, {"name" : "John", "language":"English"}, {"name" : "Jan", "language":"Czech"}]}' http://localhost:8080/jsongreetbidistream
Log after curl executed:
{"id":"403876ed-0db4-40ca-a19c-158f563fef16","workflowdata":{"helloRequests":[{"name":"Javierito","language":"Spanish"},{"name":"John","language":"English"},{"name":"Jan","language":"Czech"}],"response":[{"message":"Saludos desde gRPC service Javierito"},{"message":"Hello from gRPC service John"},{"message":"Hello from gRPC service Jan"}]}}
Notice that this time individual corresponding greetings were received.
The service based on the JSON workflow definition can be accessed by sending a request to http://localhost:8080/jsongreetbidistreamerror with the same content as the bidirectional scenario. Log after curl executed is:
{"failedNodeId":"_jbpm-unique-4","id":"edcb844c-87db-4660-af17-ebe1cc853e0a","message":"io.grpc.StatusRuntimeException - OUT_OF_RANGE"}