You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@flink.apache.org by Noel OConnor <no...@gmail.com> on 2022/12/07 14:14:08 UTC

Accessing kafka message key from a KafkaSource

Hi,
I'm using a kafka source to read in messages from kafka into a datastream.
However I can't seem to access the key of the kafka message in the datastream.
Is this even possible ?

cheers
Noel

Re: Accessing kafka message key from a KafkaSource

Posted by Noel OConnor <no...@gmail.com>.
Thanks, I'll try that.

On Wed, Dec 7, 2022 at 7:19 PM Yaroslav Tkachenko <ya...@goldsky.com> wrote:
>
> Hi Noel,
>
> It's definitely possible. You need to implement a custom KafkaRecordDeserializationSchema: its "deserialize" method gives you a ConsumerRecord as an argument so that you can extract Kafka message key, headers, timestamp, etc.
>
> Then pass that when you create a KafkaSource via "setDeserializer" method.
>
> On Wed, Dec 7, 2022 at 6:14 AM Noel OConnor <no...@gmail.com> wrote:
>>
>> Hi,
>> I'm using a kafka source to read in messages from kafka into a datastream.
>> However I can't seem to access the key of the kafka message in the datastream.
>> Is this even possible ?
>>
>> cheers
>> Noel

Re: Accessing kafka message key from a KafkaSource

Posted by Yaroslav Tkachenko <ya...@goldsky.com>.
Hi Noel,

It's definitely possible. You need to implement a
custom KafkaRecordDeserializationSchema: its "deserialize" method gives you
a ConsumerRecord as an argument so that you can extract Kafka message key,
headers, timestamp, etc.

Then pass that when you create a KafkaSource via "setDeserializer" method.

On Wed, Dec 7, 2022 at 6:14 AM Noel OConnor <no...@gmail.com> wrote:

> Hi,
> I'm using a kafka source to read in messages from kafka into a datastream.
> However I can't seem to access the key of the kafka message in the
> datastream.
> Is this even possible ?
>
> cheers
> Noel
>