Deserialization PRIMITIVE AVRO KEY in KStream APP

瘦欲@ 提交于 2019-12-11 18:46:37

问题


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

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

when i use the kafka-avro-console-consumer, I can see that the key is correctly deserialize

But impossible to make it work in a KSTREAM app

the avro schema of the key is a PRIMITIVE:

{"type":"string"}

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

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

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 ]


回答1:


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

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

Thiyaga Rajan proposed a working implementation

Serde class for AVRO primitive type



来源:https://stackoverflow.com/questions/57220008/deserialization-primitive-avro-key-in-kstream-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!