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:devThis will start the application in the Confluent schema registry compatibility mode.
To use the Apicurio Avro Serializer and Deserializer:
-
Open the
application.propertiesfile -
Uncomment the
value.serializerproperties to use theio.apicurio.registry.serde.avro.AvroKafkaSerializerandio.apicurio.registry.serde.avro.AvroKafkaDeserializerclasses 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
apicurioregistrymp.messaging.incoming.price-in.apicurio.registry.url=http://localhost:8081/apis/registry/v2 -
Comment the property using the
schemaregistry# 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