Created
November 20, 2018 20:18
-
-
Save brachi-wernick/a5e832d6fa7c4bb45bb748185202192f to your computer and use it in GitHub Desktop.
registerSchema.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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