gpt4 book ai didi

java - 使用kafka lib反序列化PRIMITIVE AVRO KEY

转载 作者:行者123 更新时间:2023-12-02 02:32:58 24 4
gpt4 key购买 nike

我目前无法在 KSTREAM 应用程序中反序列化 avro PRMITIVE key

使用 avro 架构编码的 key (在架构注册表中注册),

当我使用 kafka-avro-console-consumer 时,我可以看到 key 已正确反序列化

但不可能让它在 KSTREAM 应用程序中运行

key 的 avro 模式是一个原语:

{"type":"string"}

我已经遵循了 confluence 的文档

final Serde<V> valueSpecificAvroSerde = new SpecificAvroSerde<>();
final Map<String, String> serdeConfig = Collections.singletonMap(SCHEMA_REGISTRY_URL_CONFIG, schemaRegistryUrl);
valueSpecificAvroSerde.configure(serdeConfig, false);

final Serdes.StringSerde keySpecificAvroSerde = new Serdes.StringSerde();
keySpecificAvroSerde.configure(serdeConfig, true);

Consumed<String, totoAvro> inputConf = Consumed.with(keySpecificAvroSerde, valueSpecificAvroSerde);

final KStream<String, totoAvro> mystream = builder.stream("name topic", inputConf);

mystream.peek((key, value) -> logger.info("topic KEY :" + key))

它对于值来说效果很好,但是键将是一个包含模式注册表中的字节的字符串,而不仅仅是“卷轴”键

https://docs.confluent.io/current/schema-registry/serializer-formatter.html#wire-format

所以字符串键是 /§/./11016015201 ,但我想要卷轴值:1016015201

如果我打印字符串内的字节,则为 [ 0x00 0x00 0x00 0x02 0x31 0x14 0x31 0x30 0x31 0x36 0x30 0x31 0x35 0x32 0x30 0x31 ]

最佳答案

更新

现在正在工作:https://stackoverflow.com/a/51957801/6227500

原始答案

该功能当前在架构注册表项目中不可用。

但是通过实现自定义 SERDE,您可以管理这种情况,

Thiyaga Rajan 提出了一个可行的实现

Serde class for AVRO primitive type

关于java - 使用kafka lib反序列化PRIMITIVE AVRO KEY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57220008/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com