英文:
Retrieve Schema From Confluent Schema Registry
问题
我正在尝试从模式注册表中获取与Kafka主题关联的模式主题版本。我可以使用 client.register(schema-name, schema)
成功地发布新版本,但我不确定如何检索版本。我尝试了下面的 curl 请求,但结果立即返回 -1(空)。
CachedSchemaRegistryClient client = new CachedSchemaRegistryClient(schemaRegistryUrl, 20);
// curl -X GET http://schema.registry.url:8888/subjects/{topic}/versions/
String command = "curl -X GET --header 'Accept: application/vnd.schemaregistry.v1+json' 'https://schema.registry.url:8888/api/schema-proxy/subjects/mytopic-value/versions'";
Process process = Runtime.getRuntime().exec(command);
Reader reader = new InputStreamReader(process.getInputStream());
int result;
while ((result = reader.read()) != -1) { // 未打印任何内容
System.out.println(result);
}
我该如何修复这个 GET 请求,或者更好的方法是,我应该如何使用模式注册表 client
来检索模式?
英文:
I'm trying to retrieve schema subject versions given a kafka topic from a schema registry. I can successfully POST a new version with client.register(schema-name, schema)
, but I'm not sure how to retrieve the versions. I tried below using a curl request, but the result hits -1 immediately (empty).
CachedSchemaRegistryClient client = new CachedSchemaRegistryClient(schemaRegistryUrl, 20);
// curl -X GET http://schema.registry.url:8888/subjects/{topic}/versions/
String command = "curl -X GET --header 'Accept: application/vnd.schemaregistry.v1+json' 'https://schema.registry.url:8888/api/schema-proxy/subjects/mytopic-value/versions'";
Process process = Runtime.getRuntime().exec(command);
Reader reader = new InputStreamReader(process.getInputStream());
int result;
while ((result = reader.read()) != -1){ // Nothing printed
System.out.println(result);
}
How can I fix this GET request, or better yet, how should I use the schema registry client
to retrieve a schema?
答案1
得分: 0
使用以下方式找到答案:
SchemaMetadata sm = client.getLatestSchemaMetadata(schemaName);
System.out.println(sm.getSchema());
英文:
Figured it out using:
SchemaMetadata sm = client.getLatestSchemaMetadata(schemaName);
System.out.println(sm.getSchema());
专注分享java语言的经验与见解,让所有开发者获益!
评论