Pubsub avro 模式测试:“消息对模式无效”

问题描述 投票:0回答:1

我正在尝试在 pubsub 中创建一个模式,我计划在创建主题时使用它。 我的 avro 架构是嵌套的,它看起来像这样:

  "type" : "record",
  "name" : "topLevelRecord",
  "fields" : [ {
    "name" : "dT_AssignmentExt",
    "type" : [ {
      "type" : "array",
      "items" : [ {
        "type" : "record",
        "name" : "dT_AssignmentExt",
        "namespace" : "topLevelRecord",
        "fields" : [ {
          "name" : "arrivalStation",
          "type" : [ "string", "null" ]
        }, {
          "name" : "arrivalTime",
          "type" : [ "string", "null" ]
        } ]
      }, "null" ]
    }, "null" ]
  }, {
    "name" : "dT_PlanHeaderExt",
    "type" : [ {
      "type" : "record",
      "name" : "dT_PlanHeaderExt",
      "namespace" : "topLevelRecord",
      "fields" : [ {
        "name" : "created",
        "type" : [ "string", "null" ]
      }, {
        "name" : "endDate",
        "type" : [ "string", "null" ]
      }, {
        "name" : "startDate",
        "type" : [ "string", "null" ]
      } ]
    }, "null" ]
  }, {
    "name" : "dT_RotationHeaderExt",
    "type" : [ {
      "type" : "record",
      "name" : "dT_RotationHeaderExt",
      "namespace" : "topLevelRecord",
      "fields" : [ {
        "name" : "locomotiveId",
        "type" : [ "string", "null" ]
      }, {
        "name" : "locomotiveType",
        "type" : [ "string", "null" ]
      } ]
    }, "null" ]
  } ]
}

它通过了验证,但是当我尝试测试一条消息时它失败了:

Message is invalid against schema.
我尝试测试的消息如下:

 "dT_AssignmentExt": [
    {
       "arrivalStation": "DE.AM",
       "arrivalTime": "2023-03-01T10:33:00Z"
    },
    {
       "arrivalStation": "DE.AM",
       "arrivalTime": "2023-03-13T15:00:00Z"
    }, 
    {
       "arrivalStation": "PHM",
       "arrivalTime": "2023-03-14T00:51:00Z"
    }, 
    {
       "arrivalStation": "MGB",
       "arrivalTime": "2023-03-14T01:17:00Z"
    }
 ],
 "dT_PlanHeaderExt": 
 {
    "created": "2023-03-01T11:32:00Z",
    "endDate": "2023-03-15T11:32:00Z",
    "startDate": "2023-03-01T11:32:00Z"
 },
 "dT_RotationHeaderExt": 
 {
    "locomotiveId": "5405",
    "locomotiveType": "BR185"
 }
}

{
  "dT_PlanHeaderExt": 
     {
        "created": "2023-03-01T11:32:00Z",
        "endDate": "2023-03-15T11:32:00Z",
        "startDate": "2023-03-01T11:32:00Z"
     }
}

pubsub 能够处理嵌套的 avro 还是我做错了什么?

nested schema avro google-cloud-pubsub
1个回答
0
投票

消息没有正确指定联合字段的值。请参阅Avro 规范

例如

locomotiveId
需要指定为:

"locomotiveId": {
  "string": "5405"
}
© www.soinside.com 2019 - 2024. All rights reserved.