An example which shows how to use the Apache Avro dataformat with Camel with the use of Apicurio Registry
The application is configured to create the schema in apicurio registry if it doesn’t exist. This schema is then used to serialize and deserialize the Employee instance from/to a kafka topic. A new Employee instance is periodically serialized into a configured topic by one camel route and consumed, deserialized and printed to the log by the second route.
See the configuration file and the schema definition for more info.
Start the apicurio registry in a docker container:
docker run -d -p 8080:8080 apicurio/apicurio-registry-mem:2.4.3.Final
Start the kafka broker:
docker run -d -e ALLOW_PLAINTEXT_LISTENER=yes -e KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092 -e KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=true -p 9092:9092 bitnami/kafka:latest
You can run this example using
mvn spring-boot:run
You will see that each 5 seconds a new employee is created and received and printed to the application log:
New employee: {"firstName": "Buster", "lastName": "Upton", "hireDate": 1669040550701, "personal": {"phone": "1-628-816-1593", "address": "642 Crist Knolls"}} New employee: {"firstName": "Genevie", "lastName": "Connelly", "hireDate": 1676979164176, "personal": {"phone": "111-242-0401", "address": "0423 Jared Junctions"}} New employee: {"firstName": "Jefferson", "lastName": "Harber", "hireDate": 1659042443546, "personal": {"phone": "121.056.5072", "address": "8466 Tamisha Meadows"}} New employee: {"firstName": "Wilburn", "lastName": "Lakin", "hireDate": 1666498121570, "personal": {"phone": "762.365.2778", "address": "9207 Schumm Point"}} ...
First, start with creating a new OpenShift project:
oc new-project csb-example-avro
Start a new deployment for the apicurio registry:
oc new-app apicurio/apicurio-registry-mem:2.4.3.Final
Deploy Kafka using OperatorHub:
oc process -f src/main/resources/openshift/kafka-template.yml -p STARTING_CSV=$(oc get packagemanifests strimzi-kafka-operator -o jsonpath='{.status.channels[?(@.name=="stable")].currentCSV}') | oc create -f -
The application is deployed using the openshift-maven-plugin
that takes care of creating all the necessary OpenShift resources.
Simply use the following command to deploy the application:
mvn clean package -Popenshift
After the application pod reaches the Ready
state you will see the expected output in the application’s pod log.
If you hit any problem using Camel or have some feedback, then please let us know.
We also love contributors, so get involved :-)
The Camel riders!