9.10. Avro架构注册表转换器¶
Avro架构注册表转换器处理写入的数据 Apache Avro 使用合流架构注册表。模式注册表是版本化Avro模式的集中存储。
要使用Avro转换器,请指定 type = "avro-schema-registry"
在您的转换器定义中。
请注意,Confluent需要Avro 1.8和Confluent客户端JAR,它们没有与GeoMesa捆绑在一起。
9.10.1. 配置¶
Avro架构注册表转换器支持使用合流架构注册表解析Avro数据。配置架构注册表集 schema-registry = "<URL of schema registry>"
在您的转换器定义中。
正在解析的Avro记录可用于字段转换,如 $1
。
9.10.2. 用法示例¶
对于本例,我们将假设在模式注册表中将以下Avro模式注册为版本1:
{
"namespace": "org.locationtech",
"type": "record",
"name": "SchemaRegistryMessageV1",
"fields": [
{
"name": "lat",
"type": "Double"
},
{
"name": "lon",
"type": "Double"
}
]
}
我们还假设在模式注册表中将以下Avro模式注册为版本2:
{
"namespace": "org.locationtech",
"type": "record",
"name": "SchemaRegistryMessageV2",
"fields": [
{
"name": "lat",
"type": "Double"
},
{
"name": "lon",
"type": "Double"
},
{
"name": "extra",
"type": "String"
}
]
}
以下是使用架构版本1:编码的Avro记录示例
{
"lat": 45.0,
"lon": 45.0
}
以下是使用模式版本2:编码的Avro记录示例
{
"lat": 45.0,
"lon": 45.0,
"extra": "Extra Test Field"
}
假设我们想要将我们的Avro记录转换为简单的功能。我们注意到,在两个模式版本之间有3个属性:
稍后
长
额外的
以下转换器配置足以解析使用架构注册表中定义的多个架构版本编码的AVRO记录:
{
type = "avro-schema-registry"
schema-registry = "http://localhost:8080"
sft = "testsft"
id-field = "uuid()"
fields = [
{ name = "lat", transform = "avroPath($1, '/lat')" },
{ name = "lon", transform = "avroPath($1, '/lon')" },
{ name = "extra", transform = "avroPath($1, '/extra')",
{ name = "geom", transform = "point($lon, $lat)" }
]
}
请注意,在简单的功能中, extra
对于使用架构版本1编码的Avro记录,该字段将为空;对于使用架构版本2编码的记录,该字段将被填充。