Plugin to interact with schema-registry using API Schema registry.
Simplify schema registration under specific subjects (topic names) and conduct seamless compatibility checks. This plugin streamlines the integration of Avro schemas, enhancing your local testing process and ensuring smooth execution in integration tests and CI pipelines. Use it now to effortlessly manage enrollment and schema validation in your Kafka ecosystem!
This plugin is licensed under the MIT License - see the License file for details.
The plugin simplifies kafka consumer testing when using avro schemas, and also provides additional features such as compatibility check. It can be used in local testing, as well as in integration tests or CI.
Features:
- registration of schemes under subjects
- compatibility check
build.gradle.kts:
plugins {
id("io.github.rudikone.avroschema-wizard-plugin") version <version>
}
avroWizardConfig {
schemaRegistryUrl = "http://localhost:8081"
configs {
topic("my-first-topic") {
searchAvroFilePath = "$projectDir/src/main/resources/avro"
protocol = "ExampleProtocol"
schema = "FirstExampleRecordFromProtocol"
subjectNameStrategy = "TopicNameStrategy"
}
topic("my-second-topic") {
searchAvroFilePath = "$projectDir/src/main/resources/avro"
protocol = "ExampleProtocol"
schema = "SecondExampleRecordFromProtocol"
subjectNameStrategy = "RecordNameStrategy"
}
topic("my-third-topic") {
searchAvroFilePath = "$projectDir/src/main/resources/avro"
schema = "Example"
}
}
}
OR
plugins {
id("io.github.rudikone.avroschema-wizard-plugin") version <version>
}
avroWizardConfig {
schemaRegistryUrl.set("http://localhost:8081")
configs {
create("my-first-topic") {
searchAvroFilePath.set("$projectDir/src/main/resources/avro")
protocol.set("ExampleProtocol")
schema.set("FirstExampleRecordFromProtocol")
subjectNameStrategy.set("TopicNameStrategy")
}
...
}
}
run
gradle registerAllSchemas
The task searches for a .avrp file with the name protocol on the path searchAvroFilePath and registers schema under the topic config name by the subjectNameStrategy strategy.
If you specify only schema and do not specify protocol, then the task searches for a .avsc file with the name schema on the path searchAvroFilePath and registers schema under the topic config name by the subjectNameStrategy strategy.
This action is performed for each topic()
configuration
Output: Registered <schema_name> with id: <id_from_registry> for <topic_name>
If a schema with the same name is registered under multiple subjects, the id will be assigned to it once. See Documentation
run
gradle checkCompatibility
The task searches for a .avrp file with the name protocol on the path searchAvroFilePath and checks if the current schema is compatible with the subject under topic config name on the subjectNameStrategy strategy.
If you specify only schema and do not specify protocol, then the task searches for a .avsc file with the name schema on the path searchAvroFilePath and checks if the current schema is compatible with the subject under topic config name on the subjectNameStrategy strategy.
This action is performed for each topic()
configuration
OR
run
gradle checkCompatibility --subject=<subject-name> --schema=<schema-name>
The task searches for topic name config with schema, then searches for a .avpr file with the name protocol on the path searchAvroFilePath and checks if the current schema is compatible with the subject.
If you specify only schema and do not specify protocol, then the task searches for a .avsc file with the name schema on the path searchAvroFilePath checks if the current schema is compatible with the subject.
If the subject does not exist, an error will be thrown!
Output: Schema <schema_name> is (not) compatible with the latest schema under subject <subject_name>
avroWizardConfig:
Name | Description | Default value | Required |
---|---|---|---|
schemaRegistryUrl | Schema registry URL | "http://localhost:10081" | - |
configs | Configs for topics | - | + |
configs:
Name | Description | Default value | Required |
---|---|---|---|
searchAvroFilePath | Directory to search for file with extension .avcs or .avpr | build directory of the project | - |
protocol | Name of .avpr file | - | - |
schema | Name of .avsc file or record in protocol | - | + |
subjectNameStrategy | Subject Name Strategy: TopicNameStrategy, RecordNameStrategy, TopicRecordNameStrategy | TopicNameStrategy | - |
See example module. Run docker-compose, testing plugin tasks. For convenience, you can use schema-registry-ui (http://localhost:8002/ in your browser).
Feel free to open an issue or submit a pull request for any bugs/improvements.