Closed chkp-rivkak closed 5 months ago
Could you please provide your produce
method too?
Sure,
Just an update - I found a workaround for this issue, I changed the code from :
await self.producer.send_and_wait(topic, message, headers)
(Full function code apears right after and wasn't changed)
to:
async def produce(self, message, topic, headers=None):
try:
logger.info(
f"Sending message {message} with headers {headers} to topic {topic} with producer {self.producer}")
await self.producer.send_and_wait(topic=topic, value=message, headers=headers)
logger.info(
f"Successfully produced message to topic '{topic}': {message}")
except Exception as e:
logger.error(f"Failed to produce message: {e}")
raise
Specifying parameters names when calling send_and_wait solved the issue for me, but it is still worth a check. Thanks!
So, you were just passing headers
into partition
argument?
Describe the bug I encountered an issue when using AIOKafkaProducer from the aiokafka library to produce messages with headers.
I create an AIOKafkaProducer instance with the following configuration:
when I produce a message without header it works, like this:
await kafka_producer_manager.produce('{"test":"test"}', 'test-topic')
Subsequently, when I attempt to produce a message with headers, like this:await kafka_producer_manager.produce('{"test":"test"}', 'test-topic', headers=[("test",b"12")])
I get this error:Expected behaviour I expected the AIOKafkaProducer to handle message production with headers without raising a TypeError. As it handles message production without headers
Environment (please complete the following information):