0

I have a protobuf model like below: i.e. protoObj

sample {
  barcode: "BAR000002"
  requisition_id: "ORDER-1"
  patient_id: "P00002"
  cancer_type: "CRC"
}
assay {
  key: "lunar2"
  title: "Lunar2"
  version: "3.0"
}
lunar2 {
  type: REPORT_TYPE_COMPLETED
  version: 1
  limitations: "TBD"
  disclaimers: "TBD"
  header {
    test_name: "XYZ"
    manufacturer: "ABCD"
    sofware_verision: "TBD"
    regulatory_status: "IVD"
  }
  content {
    requisition_id: "ORDER-1"
    created {
      seconds: 1631736582
      nanos: 986649036
    }
    result: "ctDNA DETECTED"
  }
}

Now I am sending this to Kafka producer as below

kafkaProducer.send('topic-test', protoObj.SerializeToString())

Now at the consumer end, I want to de-serialize it on JSON and send this JSON to downstream services, I am doing below:

 def consumerMessage(self):
        for msg in self.kafkaConsumer:
            prototype_pb2.Proto().ParseFromString(msg.value)
            print(prototype_pb2)

But I am getting the below error:

google.protobuf.message.DecodeError: Error parsing message

I don't understand where exactly is the issue. Please help.

  • The message object has a `value` method - you've used `msg.value` rather than `msg.value()`. If you make that change and retry, what do you see? – James McPherson Sep 28 '21 at 06:47
  • Thanks! but I had a different implementation where I am de-serializing and converting the data into JSON using MessageToJson() – suyashnatural Sep 29 '21 at 14:58

0 Answers0