Skip to content

Latest commit

 

History

History
81 lines (51 loc) · 3.13 KB

README.adoc

File metadata and controls

81 lines (51 loc) · 3.13 KB

Camel Kafka example

Introduction

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.

Trying out the example on your local machine

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

How to run the example

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"}}
...

Trying out the example on OpenShift

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 -

How to run

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.

Help and contributions

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!