I am building a dead letter queue. What I am interested in implementing is the ability to forward a message in its entirety to another queue (when there is, for example, an error). In other words, I am interested in preserving the metadata of the message as well as its contents.
Here is some code to highlight the issue:
from confluent_kafka import Producer
producer = Producer({'bootstrap.servers': "host1:9092",'client.id': '0', 'auto.offset.reset': 'smallest'})
while True:
msg = consumer.poll(timeout=1)
if msg is None:
continue
else:
producer.produce(topic='test_topic', value=msg )
However, I am unable to send this message. Converting the message to json returns the following when producing a message:
TypeError: Object of type Message is not JSON serializable
. If I try serializing to JSON - then it seems I am not able to get the full representation of the message using json.
I am using confluent kafka pytrhon. This is the consumer - https://github.com/confluentinc/confluent-kafka-python/blob/a5663da7ea76e58d02b13e4e6703ea6a9c52ec11/src/confluent_kafka/src/Consumer.c. Producer - https://github.com/confluentinc/confluent-kafka-python/blob/a5663da7ea76e58d02b13e4e6703ea6a9c52ec11/src/confluent_kafka/src/Producer.c
How would I be able to forward a message from one queue to another while including the message metadata?