【问题标题】:Deserialize Avro message with schema type as object反序列化具有模式类型作为对象的 Avro 消息
【发布时间】:2020-07-08 11:35:30
【问题描述】:

我正在阅读包含 Avro 消息的 Kafka 主题。我给出了以下架构。 我无法解析架构和反序列化消息。

{
  "type": "record",
  "name": "Request",
  "namespace": "com.sk.avro.model",
  "fields": [
    {
      "name": "empId",
      "type": [
        "null",
        "string"
      ],
      "default": null,
      "description": "REQUIRED "
    },
    {
      "name": "carUnit",
      "type": "com.example.CarUnit",
      "default": "ABC",
      "description": "Car id"
    }
  ]
}

我遇到以下错误:

The type of the "carUnit" field must be a defined name or a {"type": ...} expression

谁能帮帮忙。

【问题讨论】:

  • 你能分享com.example.BusinessUnit的定义吗?
  • 我在主请求中有类似的子对象。
  • @GiorgosMyrianthous ,你能指导我反序列化消息吗?您是否还可以为 avro 消息生产者和消费者提供任何参考链接。

标签: apache-kafka deserialization kafka-consumer-api avro


【解决方案1】:

怎么样

{
    "name": "businessUnit",
    "type": { 
        "type": { 
            "type": "record ", 
            "name": "BusinessUnit ", 
            "fields": [{ 
                "name": "hostName ", 
                "type": "string " 
             }] 
         } 
     } 
 }

【讨论】:

  • 如果我们没有每种类型的定义,我们能否拥有类似通用记录的东西。您能否提供代码 sn-p 来创建通用记录以解析模式
  • @SreenivasK Avro 需要严格输入。您可以获得的最通用的是map 记录
猜你喜欢
  • 1970-01-01
  • 2021-09-06
  • 2021-10-04
  • 1970-01-01
  • 2017-06-29
  • 2020-06-06
  • 1970-01-01
  • 2011-09-29
  • 1970-01-01
相关资源
最近更新 更多