I am pretty new to the confluent-kafka and python, just would like to know if there a way in python we could serialize the python class to an kafka message using avro schema.
I am currently using AvroProducer provided by confluent-kafka, however, i am only able tot serialize a json string. And the downstream application is using Java, and downstream would like to deserialize the message back to an Java Object.
producer = AvroProducer(self.producer_config, default_key_schema=key_schema, default_value_schema=value_schema)
value = ast.literal_eval(str(message))
try:
producer.produce(topic=topic, partition=partition, key=str(message['Id']),
value=value)
I believe this is the part that is causing issue:
value = ast.literal_eval(str(message))
The message is originally a dictionary. I have to convert it to a json string in order to serialize it. It just looks really weird.
Could you help advise how to serialie a python class, instead of serialize a json string using AvroProducer? Thanks!