我们可以使用" oneOf"在Confluent Platform架构注册表中?

时间:2017-01-05 06:00:06

标签: json apache-kafka avro confluent

我有一个用户余额更改的用例。我想将所有用户余额事件放在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用例的地方。有没有办法使用它?

1 个答案:

答案 0 :(得分:0)

这可行:

{
"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"}
                        ]
                     }
             ]
        }
    ]
}