Skip to content

Instantly share code, notes, and snippets.

@brachi-wernick
Created November 20, 2018 20:18
Show Gist options
  • Save brachi-wernick/a5e832d6fa7c4bb45bb748185202192f to your computer and use it in GitHub Desktop.
Save brachi-wernick/a5e832d6fa7c4bb45bb748185202192f to your computer and use it in GitHub Desktop.
registerSchema.java
public static void registerSchema(String topic,String schemaPath, String schemaUrl) throws IOException, RestClientException {
// subject convention is "<topic-name>-value"
String subject = topic + "-value";
String schema;
FileInputStream inputStream = new FileInputStream(schemaPath);
try {
schema = IOUtils.toString(inputStream);
} finally {
inputStream.close();
}
Schema avroSchema = new Schema.Parser().parse(schema);
CachedSchemaRegistryClient client = new CachedSchemaRegistryClient(schemaUrl, 20);
client.register(subject, avroSchema);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment