java - 使用 Hortonworks 架构注册表读取 Java 应用程序中的 Avro 文件

标签 java avro hortonworks-data-platform

我有一个正在以 Avro 格式写入文件的应用程序(每个文件有多个记录),但我无法在另一个 Java 应用程序中读取它。这是我尝试过的

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);

但是它抛出

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)

我知道您很难重现此问题,因为它需要我的架构注册表和文件。但我希望我在这里做了一些愚蠢的事情。任何帮助,将不胜感激。

最佳答案

好的...我已经意识到错误消息中的 79 是字母 OASCII 代码。然后我仔细检查我的文件是否真的使用架构注册表 - 事实证明它们没有。它们只是具有嵌入式架构的 Avro 文件。因此,我不需要 Hortonworks 的 AvroSnapshotDeserializer - 简单的 DataFileReader 就可以了。

关于java - 使用 Hortonworks 架构注册表读取 Java 应用程序中的 Avro 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60899888/

相关文章:

java - 了解神经网络层、节点和点积

java - 更改 JAVA_HOME 以匹配您的环境 JAVA_HOME ="/opt/java"

json - 使用 Avro Schema 验证 Json 文件

hadoop - ambari-agent 不再能够联系位于 http ://<dom>:8440? 的服务器

scala - 大量插入到 HBase

java - Vert.x Web(Scala): Read Multipart File Upload as Stream from Router without Saving to Disk

java - 将字符串存储到永久变量问题

python - 如何在 Python 中从 S3 读取 Avro 文件?

azure - 在 Azure HDI4.0 中读取 Avro

hadoop - 在 HDP-1.3.3 上使用 kerberos 的 Oozie 配置单元操作