How to decode/deserialize Avro with Python from Kafka

后端 未结 2 471
情话喂你
情话喂你 2020-12-11 07:40

I am receiving from a remote server Kafka Avro messages in Python (using the consumer of Confluent Kafka Python library), that represent clickstream data with json dictionar

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-11 08:25

    If you use Confluent Schema Registry and want to deserialize avro messages, just add message_bytes.seek(5) to the decode function, since Confluent adds 5 extra bytes before the typical avro-formatted data.

    def decode(msg_value):
        message_bytes = io.BytesIO(msg_value)
        message_bytes.seek(5)
        decoder = BinaryDecoder(message_bytes)
        event_dict = reader.read(decoder)
        return event_dict
    

提交回复
热议问题