【问题标题】:Can we use "oneOf" in Confluent Platform Schema Registry?我们可以在 Confluent Platform Schema Registry 中使用“oneOf”吗?
【发布时间】:2017-01-05 06:00:05
【问题描述】:

我有一个用户余额更改的用例。我想将所有用户平衡事件放在 1 个主题中。但是由于推荐奖金、获胜奖金、提款、存款等多种事件,用户余额正在发生变化。这可以通过这样的嵌套记录来实现:

{
"name": "userBalance",
"type": "record",
"fields": [
       {
            "name": "cashDeposit",
            "type": 
                   {
                        "type" : "record",
                        "name" : "userCashDeposit",
                        "fields" : [
                            {"name": "id", "type": "long"},
                            {"name": "amount", "type": "float"}
                        ]
                    }
        },
        {
            "name": "cashWithdraw",
            "type": {
                        "type" : "record",
                        "name" : "userCashWithdraw",
                        "fields" : [
                            {"name": "id", "type": "long"},
                            {"name": "amount", "type": "float"}
                        ]
                    }
        }
    ]
}

但这使得所有嵌套记录都按要求进行,而我想严格执行这些事件中的任何一个都存在于事件中,并严格遵守该事件的记录。 Avro 模式支持“oneOf”,但我找不到在任何地方用于 Confluent Schema Registry 用例的 oneOf。有什么方法可以使用吗?

【问题讨论】:

    标签: json apache-kafka avro confluent-platform


    【解决方案1】:

    这可以工作:

    {
    "name": "userBalance",
    "type": "record",
    "fields": [
           {
                "name": "userBalance",
                "type": [
                       {
                            "type" : "record",
                            "name" : "userCashDeposit",
                            "fields" : [
                                {"name": "id", "type": "long"},
                                {"name": "amount", "type": "float"}
                            ]
                        },
                        {
                             "type" : "record",
                            "name" : "userCashWithdraw",
                            "fields" : [
                                {"name": "id", "type": "long"},
                                {"name": "amount", "type": "float"}
                            ]
                         }
                 ]
            }
        ]
    }
    

    【讨论】:

      猜你喜欢
      • 2021-01-10
      • 1970-01-01
      • 2021-10-04
      • 2017-12-17
      • 2021-05-11
      • 1970-01-01
      • 2019-05-01
      • 2023-01-11
      • 2016-12-31
      相关资源
      最近更新 更多