0

I have passed a Protobuf object in a Kafka producer and am receiving a byte array on the consumer side. Now I want to deserialize that response again back to a Protobuf object, but I am unable to do that. How can I do that?

Here is my consumer:

from email import message
from kafka import KafkaConsumer
import json
from simple import simple_message
import check_pb2

consumer = KafkaConsumer('latest', api_version=(0, 10, 1),
                         group_id='my-group', enable_auto_commit=False,
                         bootstrap_servers=['localhost:9092'])#,
           #value_deserializer=lambda m: json.loads(m.decode('ascii')))
for message in consumer:
    print(message)

I tried to use Confluent but getting

Kafka Exception : {} KafkaError{code=_VALUE_DESERIALIZATION,val=-159,str="Unknown magic byte. This message was not produced with a Confluent Schema Registry serializer"

0

1 Answer 1

1

If you're not using Confluent Schema Registry, use ParseFromString.

for message in consumer:
    value = ParseFromString(message.value)  # example 
    print(value)

If (and only if) you are using the Schema Registry, then Confluent has a Protobuf deserializer class. See the example, which happens to also use ParseFromString internally.

Sign up to request clarification or add additional context in comments.

8 Comments

tried to use confulent but getting Kafka Exception : {} KafkaError{code=_VALUE_DESERIALIZATION,val=-159,str="Unknown magic byte. This message was not produced with a Confluent Schema Registry serializer"
Your producer would need to use the registry as well.
my producer is a java service and i do not have control over it
can you tell me some way to do that
my java part has no schema regitry, can you tell me how can i do that without confluent deserializer ,/
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.