This is a simple example of how to build a Kafka producer with Quarkus and Vert.x.
This demo implements a small Quarkus App that connects to a Kafka broker and sends events to a specific topic. Events can be sent via a web frontend and via a small REST API that expose both a SmallRye Kafka producer route and a Vert.x Kafka route.
The "event" message is a JSon-formatted payload that contains
- an unique UUID that identifies an event stream
- a message string
- an event severity index (integer)
- the event timestamp
The kafka message key is set to be equal to the UUID contained in the payload.
You can run your application in dev mode that enables live coding using:
./mvnw compile quarkus:dev
Running the application in dev mode requires an already running Kafka Broker. A simple one-node broker running on localhost is enough. To install AMQ Streams on a RedHat Enterprise Linux 8 server, refer to this Ansible Playbook.
NOTE: Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/.
The application can be packaged using:
./mvnw package
It produces the quarkus-run.jar
file in the target/quarkus-app/
directory.
Be aware that it’s not an über-jar as the dependencies are copied into the target/quarkus-app/lib/
directory.
The application is now runnable using java -jar target/quarkus-app/quarkus-run.jar
.
If you want to build an über-jar, execute the following command:
./mvnw package -Dquarkus.package.type=uber-jar
The application, packaged as an über-jar, is now runnable using java -jar target/*-runner.jar
.
Some simple automated tests are shipped as JUnit test cases. To run tests simply use maven:
./mvnw clean test
An embedded Kafka Cluster is automatically started as a Quarkus Resource for the Test Lifecycle Manager.
You can create a native executable using:
./mvnw package -Pnative
Or, if you don't have GraalVM installed, you can run the native executable build in a container using:
./mvnw package -Pnative -Dquarkus.native.container-build=true
You can then execute your native executable with: ./target/consumer-1.0.0-SNAPSHOT-runner
If you want to learn more about building native executables, please consult https://quarkus.io/guides/maven-tooling.html.
Please follow the steps described here to deploy the CI environment. The repo contains automation that deploys the CI env, the application manifests and the tektok pipeline used to build the app itself.
- RESTEasy JAX-RS (guide): REST endpoint framework implementing JAX-RS and more
- Kafka for JUnit (docs): Embedded Kafka for JUnit
- Vert.x under Quarkus (docs): Use Vert.x under Quarkus reference docs
- Quarkus Kafka Guide (docs): Guide for using Kafka under Quarkus
The application comes with a simple Angular frontend listening on the default quarkus HTTP server port:
Both (microprofile and vert.x) REST API endpoints are also available for automated interaction:
- Vert.x endpoint:
curl -v http://localhost:8080/vertx/post -XPOST -d'{ "id": "1c51a259-29e7-454d-b9dc-b7616d727ff1", "message": "TestMessageJUnit", "severity": 1, "event_timestamp": 1636720919565 }' -H 'Content-Type: application/json'
- Microprofile Endpoint:
curl -v http://localhost:8080/producer/post -XPOST -d'{ "id": "1c51a259-29e7-454d-b9dc-b7616d727ff1", "message": "TestMessageJUnit", "severity": 1, "event_timestamp": 1636720919565 }' -H 'Content-Type: application/json'
Container image build pipelines currently require the privileged SCC to be attached to the 'pipeline' ServiceAccount in order to successfully run:
oc adm policy add-scc-to-user privileged -z pipeline
``