confluentinc / confluent-kafka-dotnet

Confluent's Apache Kafka .NET client
https://github.com/confluentinc/confluent-kafka-dotnet/wiki
Apache License 2.0
35 stars 854 forks source link

Feature request: Allow value deserializer access to key #1528

Open mat8913 opened 3 years ago

mat8913 commented 3 years ago

I have an application which needs to look at the key first before deserializing the rest of the message. Would you be opposed to a PR adding the key to SerializationContext?

mhowlett commented 3 years ago

you'd need to pass the bytes, not the deserialized key because the serialization context is also passed when deserializing the key and also, it's not a generic type, which it ideally would be. and if you're passing the key, probably also pass the value for completeness (though i expect that wouldn't be used).

if there's no alternative to satisfying an important use-case i'd probably be happy to, but i'm not convinced.

mat8913 commented 3 years ago

I've found a good workaround for my use case: I just use IConsumer<byte[], byte[]> and then do the actual deserialization in my own code.

filipeesch commented 3 years ago

I've found a good workaround for my use case: I just use IConsumer<byte[], byte[]> and then do the actual deserialization in my own code.

Hi @mat8913 did you look at KafkaFlow framework? There the Serialization is made by a middleware, so you can create your own serialization middleware or use one provided by the framework with a custom Type Resolver. Look here: https://github.com/farfetch/kafka-flow