我们可以在confluent platform schema registry中使用“oneof”吗?

mefy6pfw  于 2021-06-07  发布在  Kafka
关注(0)|答案(1)|浏览(413)

我有一个用户平衡变化的用例。我想把所有用户平衡事件放在一个主题中。但用户余额的变化是发生在多个事件,如推荐奖金,奖金,取款,存款。这可以通过以下嵌套记录实现:

{
"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”,但我找不到用于合流模式注册表用例的oneof。有什么办法用吗?

fumotvh3

fumotvh31#

这可以工作:

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

相关问题