Kafka Connect 是否支持枚举? [英] Does Kafka Connect support enums?

查看:28
本文介绍了Kafka Connect 是否支持枚举?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Kafka Connect 是否支持枚举字段?如果没有,通常的解决方法是什么?我在这里查看 Kafka 2.6.0 ConnectSchema API:https://kafka.apache.org/26/javadoc/org/apache/kafka/connect/data/ConnectSchema.html

Are enum fields supported in Kafka Connect? If not, what is the usual workaround? I'm looking at the Kafka 2.6.0 ConnectSchema API here: https://kafka.apache.org/26/javadoc/org/apache/kafka/connect/data/ConnectSchema.html

我正在尝试通过使用 Confluent Schema 注册表(带有 AVRO)来遵循最佳实践,但似乎无法让我的自定义源连接器生成包含枚举以匹配现有模式的模式(输出主题有其他除连接器外的生产者).一种解决方法是简单地使用字符串,但这会破坏架构的全部意义,不是吗?

I'm trying to follow best practice by using the Confluent Schema registry (with AVRO), but can't seem to get my custom source connector to generate a schema containing enums to match an existing schema (the output topic has other producers besides the connector). A work-around would be to simply use strings, but that undermines the whole point of a schema, doesn't it?

推荐答案

没有通用的方法,但是在 AVRO 的情况下可以使用转换器特定的特殊配置,然后还必须提供特殊提示通过枚举字段架构属性.我能够使用自定义连接转换提供提示.

There is not an approach that works in general, but you can use a converter specific special configuration in the case of AVRO, and then you must also provide special hints via the enum field Schema properties. I was able to provide the hints using a custom Connect Transform.

使用以下命令配置 Connect 转换器:

Configure the Connect converter with:

"value.converter": "io.confluent.connect.avro.AvroConverter",
"value.converter.schema.registry.url": "http://registry:8081",
"value.converter.enhanced.avro.schema.support":  true,
"value.converter.connect.meta.data": false,
"transforms": "alarms",
"transforms.alarms.type": "org.jlab.kafka.connect.transforms.EpicsToAlarm$Value"

然后自定义转换包含:

    final Schema prioritySchema = SchemaBuilder
            .string()
            .doc("Alarm severity organized as a way for operators to prioritize which alarms to take action on first")
            .parameter("io.confluent.connect.avro.enum.doc.AlarmPriority", "Enumeration of possible alarm priorities")
            .parameter("io.confluent.connect.avro.Enum", "org.jlab.kafka.alarms.AlarmPriority")
            .parameter("io.confluent.connect.avro.Enum.1", "P1_LIFE")
            .parameter("io.confluent.connect.avro.Enum.2", "P2_PROPERTY")
            .parameter("io.confluent.connect.avro.Enum.3", "P3_PRODUCTIVITY")
            .parameter("io.confluent.connect.avro.Enum.4", "P4_DIAGNOSTIC")
            .build();

完整转换源

这篇关于Kafka Connect 是否支持枚举?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆