简体   繁体   English

使用 Hortonworks Schema Registry 读取 Java 应用程序中的 Avro 文件

[英]Reading Avro files in Java application with Hortonworks Schema Registry

I have an application that is writing files in Avro format (multiple records per file) but I cannot read it in another Java app.我有一个应用程序以 Avro 格式写入文件(每个文件有多个记录),但我无法在另一个 Java 应用程序中读取它。 Here's what I've tried这是我尝试过的

Map<String, Object> registryConfig = new HashMap<>();
registryConfig.put("schema.registry.client.class.loader.cache.size", 10L);
registryConfig.put("schema.registry.url", "http://localhost:9090/api/v1");
registryConfig.put("schema.registry.client.class.loader.cache.expiry.interval.secs", 10L);
registryConfig.put("schema.registry.deserializer.schema.cache.size", 10L);
registryConfig.put("schema.registry.client.schema.metadata.cache.size", 10L);
registryConfig.put("schema.registry.client.schema.text.cache.expiry.interval.secs", 10000L);
registryConfig.put("schema.registry.client.schema.version.cache.expiry.interval.secs", 10000L);
registryConfig.put("schema.registry.client.schema.metadata.cache.expiry.interval.secs", 10L);
registryConfig.put("specific.avro.reader", false);
registryConfig.put("schema.registry.client.schema.version.cache.size", 10L);
registryConfig.put("schema.registry.client.schema.version.text.size", 10L);
registryConfig.put("schemaregistry.deserializer.schema.cache.expiry.secs", 10000L);

SchemaRegistryClient registryClient = new SchemaRegistryClient(registryConfig);

AvroSnapshotDeserializer deserializer = new AvroSnapshotDeserializer(registryClient);
deserializer.init(registryConfig);

Path p = Paths.get("/tmp/dump.avro");
InputStream is = Files.newInputStream(p);
deserializer.deserialize(is);

But it throws但它抛出

Exception in thread "main" com.hortonworks.registries.schemaregistry.serdes.avro.exceptions.AvroException: Unknown protocol id [79] received while deserializing the payload
  at com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotDeserializer.checkProtocolHandlerExists(AvroSnapshotDeserializer.java:70)
  at com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotDeserializer.retrieveProtocolId(AvroSnapshotDeserializer.java:63)
  at com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotDeserializer.retrieveProtocolId(AvroSnapshotDeserializer.java:32)
  at com.hortonworks.registries.schemaregistry.serde.AbstractSnapshotDeserializer.deserialize(AbstractSnapshotDeserializer.java:141)
  at com.hortonworks.registries.schemaregistry.serde.AbstractSnapshotDeserializer.deserialize(AbstractSnapshotDeserializer.java:55)
  at com.hortonworks.registries.schemaregistry.serde.SnapshotDeserializer.deserialize(SnapshotDeserializer.java:60)

I know it would be difficult for you to reproduce this problem as it requires my schema registry and a file.我知道您很难重现此问题,因为它需要我的架构注册表和文件。 I hope though, that I am doing something silly here.不过,我希望我在这里做一些愚蠢的事情。 Any help would be appreciated.任何帮助,将不胜感激。

Okay... I've realized that 79 from the error message is ASCII code of the letter O .好的...我已经意识到错误消息中的79是字母O ASCII代码。 I then double checked if my files are REALLY using schema registry - it turns out they don't.然后我仔细检查我的文件是否真的使用架构注册表 - 结果他们没有。 They are just Avro files with embedded schema.它们只是带有嵌入式架构的 Avro 文件。 Thus, I don't need Hortonworks' AvroSnapshotDeserializer - simple DataFileReader will do.因此,我不需要 Hortonworks 的AvroSnapshotDeserializer - 简单的DataFileReader就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Hortonworks Schema Registry + Nifi + Java:反序列化 Nifi 记录 - Hortonworks Schema Registry + Nifi + Java: Deserialize Nifi Record 带有avro模式注册表的Java kafka流的正确指南 - proper guide for java kafka stream with avro schema registry 使用Spark-Java读取HDFS中存储的Avro表和架构 - Reading Avro table and schema stored in HDFS using Spark- Java 如何从来自 java 消费者的主题中的消息中从模式注册表中检索 AVRO 模式 - How to retrieve AVRO Schema from Schema Registry from a message in a Topic from java consumer Spring / Avro - 使用融合模式注册表 - Spring / Avro - using confluent schema registry 使用模式注册表异常的 Avro 序列化 - Avro Serialisation using Schema Registry Exception 错误序列化 Avro 消息 - Kafka Schema Registry - Error serializing Avro message - Kafka Schema Registry Kafka Stream with Avro in JAVA , schema.registry.url&quot; 没有默认值 - Kafka Stream with Avro in JAVA , schema.registry.url" which has no default value Java gradle kafka-avro-serializer 和 kafka-schema-registry-client 在部署管道中下载失败 - Java gradle kafka-avro-serializer and kafka-schema-registry-client fails to download in the deployment pipeline 通用类型的 AVRO 模式 - Java - AVRO schema for generic type - Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM