如何将Apache Ignite缓存条目写入Apache Avro文件?

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

我现在正在做一个任务,要求我把Apache Ignite缓存存储的数据写入Avro.不幸的是,我没有访问用于创建缓存存储对象的初始Java类,我唯一的来源是Apache Ignite(它的Java API)。缓存本身的表现形式是 IgniteCache<Object, Object>. 事实上,每个缓存条目都是一个键值对,其中键值是作为一个 亲和键 and value contains a project-related object.Cache entry looks as follows when converting it to JSON:

{
    "AffinityKey [key=1, affKey=1f1a11b-ba1e-1cd1-1c11-c11111ab1111]": {
        "version": null,
        "name": "Name 1",
        "description": "Description 1",
        "interests": [
            "int1",
            "int2",
            "int3",
            "int4"
        ],
        "hobbies": [
            "hobby1",
            "hobby2",
            "hobby3"
        ],
        "classId": 11111,
        "creator": "5b90fb41e0eb212c4736d186",
        "editorId": null,
        "logoConfigurationId": 85,
        "editTimeout": null,
        "active": false,
        "lastActionTime": {
            "year": 2020,
            "month": "MAY",
            "nano": 143000000,
            "monthValue": 5,
            "dayOfMonth": 18,
            "hour": 14,
            "minute": 1,
            "second": 4,
            "dayOfYear": 139,
            "dayOfWeek": "MONDAY",
            "chronology": {
                "id": "ISO",
                "calendarType": "iso8601"
            }
        },
        "status": "Attention required",
        "lastJobId": null
    }
}

谁能告诉我如何将Ignite缓存条目序列化到Avro?据我所知,Avro序列化需要Avro-schema。为此,我需要知道缓存条目中每个字段的名称和类型。我所看到的唯一的模式创建方法是让条目-key和条目-value都表示为 二进制对象 然后收集所有的字段名和类型。有了对象字段的所有名称-类型对,也许可以手动构建某种json,以便进一步将其存储在.asvc文件中。

也许有人能提供一个更 "优雅 "的解决方案?

java avro ignite
1个回答
0
投票

有一个Ignite缓存条目表示为一个 Map<BinaryObject, BinaryObject> (.withKeepBinary() 应在向Ignite请求缓存时使用)可以提取每个BinaryObject的字段定义(字段名+字段类型)。Avro SchemaBuilder 可以进一步用于avro模式的生成。

© www.soinside.com 2019 - 2024. All rights reserved.