Use schema registry in Java with Aiven for Apache Kafka®
Aiven for Apache Kafka® provides schema registry functionality through Karapace. Karapace lets you store, retrieve, and evolve schemas without rebuilding producer or consumer code.
Workflow overview
To produce and consume Avro messages in Java using the schema registry:
- Define your schema.
- Generate Java classes from the schema.
- Add the required dependencies.
- Optional: Create a keystore, and create a truststore only if you use SASL authentication.
- Configure your Kafka producer and consumer properties.
Prerequisites
To connect a Java application to an Aiven for Apache Kafka service using the schema registry:
- Aiven Console
- Aiven CLI
- Running Aiven for Apache Kafka service
- Karapace Schema Registry enabled
- Keystore and truststore files for SSL authentication
Generate the keystore and truststore using the Aiven CLI:
avn service user-kafka-java-creds \
--project <project-name> \
--service <service-name> \
--username <user>
Variables
Replace the following placeholders in the example configuration:
| Variable | Description |
|---|---|
BOOTSTRAPSERVERS | Kafka service URI. Available in Connection information on the service overview page in the Aiven Console. |
KEYSTORE | Path to the keystore file |
KEYSTOREPASSWORD | Password for the keystore |
TRUSTSTORE | Path to the truststore file |
TRUSTSTOREPASSWORD | Password for the truststore |
SSLKEYPASSWORD | Password for the private key in the keystore |
SCHEMAREGISTRYURL | Schema Registry URI. Available in Connection information on the service overview page in the Aiven Console. |
SCHEMAREGISTRYUSER | Schema Registry username. Available in Connection information on the service overview page in the Aiven Console. |
SCHEMAREGISTRYPASSWORD | Schema Registry password. Available in Connection information on the service overview page in the Aiven Console. |
TOPIC_NAME | Kafka topic name |