When I tried to run Kafka Consumer with Avro on top of the data with the appropriate schema, it returns the error "AvroRuntimeException: garbled data. Length negative: -40". I see that others had similar problems converting the byte array to json , writing and reading Avro, and the Kafka Avro * binary encoder . I also referred to this example of a group of consumers who were all helpful, but have not yet helped with this error. It works up to this part of the code (line 73).
Decoder decoder = DecoderFactory.get (). BinaryDecoder (byteArrayInputStream, null);
I tried other decoders and printed the contents of the byteArrayInputStream variable, which looks like, in my opinion, what you expect serialized avro data to look like (in the message I see a diagram, some data and some distorted data). I printed Available bytes using the .available () method, which returns 594. I have problems understanding why this error occurs. Apache Nifi is used to create a Kafka stream with the same scheme from hdfs. I would be grateful for any help.
java apache-kafka kafka-consumer-api avro apache-nifi
Sparklegoat
source share