This project shows how to use the Apicurio Service Registry to manage Apache Kafka data schemas. This example uses the Avro data format messages to and from a local cluster.
First you need an Apache Kafka cluster. You can follow the instructions from the Apache Kafka website or use the docker-compose.yaml
file in this project.
To start the local development cluster and registry:
-
Open a terminal window and clone this GitHub repository
git clone https://github.com/hguerrero/amq-examples.git
-
Navigate to /registry-example-avro directory.
cd amq-examples/registry-example-avro
-
Be sure Docker Desktop is running.
-
Execute the following command:
docker-compose -f docker-compose.yaml up -d
-
Wait until all the components are up and running.
The application is based on Quarkus (using Java 8) so it can be started executing the following command:
./mvnw quarkus:dev
This will start the application in the Confluent schema registry compatibility mode.
To use the Apicurio Avro Serializer and Deserializer:
-
Open the
application.properties
file -
Uncomment the
value.serializer
properties to use theio.apicurio.registry.serde.avro.AvroKafkaSerializer
andio.apicurio.registry.serde.avro.AvroKafkaDeserializer
classes instead.mp.messaging.outgoing.price-out.value.serializer=io.apicurio.registry.serde.avro.AvroKafkaSerializer mp.messaging.incoming.price-in.value.deserializer=io.apicurio.registry.serde.avro.AvroKafkaDeserializer
-
Comment the same lines that use the
io.confluent.kafka.*
packages# mp.messaging.outgoing.price-out.value.serializer=io.confluent.kafka.serializers.KafkaAvroSerializer # mp.messaging.incoming.price-in.value.deserializer=io.confluent.kafka.serializers.KafkaAvroDeserializer
-
Uncomment the property using the
apicurio
registrymp.messaging.incoming.price-in.apicurio.registry.url=http://localhost:8081/apis/registry/v2
-
Comment the property using the
schema
registry# mp.messaging.incoming.price-in.schema.registry.url=http://localhost:8081/apis/ccompat/v6
To test that everything is workin start again the application with the new configuration values:
./mvnw quarkus:dev