From 692833c3eca9700881240bd5e2193bc1c073ef8c Mon Sep 17 00:00:00 2001 From: Oliver Leumann Date: Fri, 28 Jun 2024 14:59:04 +0200 Subject: [PATCH] Puplicate producing message in the most inconvenient way possible --- src/Producer/KafkaProducer.php | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Producer/KafkaProducer.php b/src/Producer/KafkaProducer.php index ae4a963..3b1e8bc 100644 --- a/src/Producer/KafkaProducer.php +++ b/src/Producer/KafkaProducer.php @@ -74,7 +74,38 @@ public function produce(KafkaProducerMessageInterface $message, bool $autoPoll = $topicProducer = $this->getProducerTopicForTopic($message->getTopicName()); - $topicProducer->producev($message->getPartition(), RD_KAFKA_MSG_F_BLOCK, + $topicProducer->producev( + $message->getPartition(), + RD_KAFKA_MSG_F_BLOCK, + $message->getBody(), + $message->getKey(), + $message->getHeaders() + ); + + // This is a test comment + if (true === $autoPoll) { + $this->producer->poll($pollTimeoutMs); + } + } + + /** + * Produces a message to the topic and partition defined in the message + * If a schema name was given, the message body will be avro serialized. + * + * @param KafkaProducerMessageInterface $message + * @param boolean $autoPoll + * @param integer $pollTimeoutMs + * @return void + */ + public function produceSameSame(KafkaProducerMessageInterface $message, bool $autoPoll = true, int $pollTimeoutMs = 0): void + { + $message = $this->encoder->encode($message); + + $topicProducer = $this->getProducerTopicForTopic($message->getTopicName()); + + $topicProducer->producev( + $message->getPartition(), + RD_KAFKA_MSG_F_BLOCK, $message->getBody(), $message->getKey(), $message->getHeaders() @@ -97,6 +128,7 @@ public function produce(KafkaProducerMessageInterface $message, bool $autoPoll = public function syncProduce(KafkaProducerMessageInterface $message): void { $this->produce($message, true, -1); + $this->produceSameSame($message, true, -1); } /**