使用 kafka lib 反序列化 PRIMITIVE AVRO KEY [英] Deserialization PRIMITIVE AVRO KEY with kafka lib

查看:37
本文介绍了使用 kafka lib 反序列化 PRIMITIVE AVRO KEY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前无法在 KSTREAM 应用程序中反序列化 avro PRIMITIVE 密钥

I'm currently incapable of deserialize an avro PRIMITIVE key in a KSTREAM APP

使用 avro 模式(在模式注册表中注册)编码的密钥,

the key in encoded with an avro schema ( registered in the schema registry ) ,

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

但不可能让它在 KSTREAM 应用程序中工作

But impossible to make it work in a KSTREAM app

键的 avro 模式是一个 PRIMITIVE:

the avro schema of the key is a PRIMITIVE:

{"type":"string"}

我已经遵循了 confluent 的文档

I already followed the documentation of confluent

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))

它对值运行良好,但键将是一个包含模式注册表中字节的字符串,而不仅仅是卷轴"键

it's working well for the value, but the key is going to be a string containing the bytes from the schema registry and not only the "reel" key

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

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

So the string key is /§/./11016015201 , but I would like the reel value : 1016015201

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

if I print the bytes inside the String it's [ 0x00 0x00 0x00 0x02 0x31 0x14 0x31 0x30 0x31 0x36 0x30 0x31 0x35 0x32 0x30 0x31 ]

推荐答案

更新

现在可以使用了:https://stackoverflow.com/a/51957801/6227500

原答案

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

The feature is not available currently in the schema registry project.

但是通过实现自定义 SERDE,您可以管理案例,

But by implementing a custom SERDE you can manage the case ,

Thiyaga Rajan 提出了一个可行的实施方案

Thiyaga Rajan proposed a working implementation

AVRO 原始类型的 Serde 类

这篇关于使用 kafka lib 反序列化 PRIMITIVE AVRO KEY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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