What is the difference between Kafka Template and kafka producer?
Asked Answered
C

2

7

As I have seen the Kafka template internally used Kafka producer. I just want to know what is the exact difference. Also, I found many send() methods available in the Kafka template as compared to Kafka producer.
Please help me with it. If anyone knows more.

Cause answered 9/9, 2020 at 8:53 Comment(0)
P
12

The producer is the pattern, while the KafkaTemplate wraps a Producer instance and provides convenience methods for sending messages to Kafka topics. (source)

The Kafka Producer is defined in Apache Kafka. The KafkaTemplate is Spring's implementation of it (although it does not implement Producer directly) and so it provides more methods for you to use. So you can use KafkaTemplate to get started or implement your own solution through implementing the Producer yourself.

Possessory answered 9/9, 2020 at 9:14 Comment(3)
Anything else as I have already gone through that source page.Cause
I added some details. I guess, KafkaTemplate is your way to go.Possessory
Spring for Apache Kafka adds familiar Spring Messaging abstractions to Kafka (KafkaTemplate, @KafkaListener - similar abstractions are available for RabbitMQ and JMS. It is a higher level abstraction. spring.io/projects/spring-kafkaKempe
B
1

Kafka Producer is the term for producer in PubSub Pattern. If you want to implement Apache Kafka using Spring, Spring has provided a wrapper around this producer which we call as Kafka Template. Kafka template is a class which spring provides to produce messages into the Kafka Topic. How Kafka Template works:: There are different layers in which Kafka Template does its tasks -

  1. SERLIALIZER Any record that we intend to send to the Kafka topic, needs to be serialised to bytes. ( 2 techniques involved - a) key.serializer b) value.serializer )
  2. Partitioner It determines in which partition the message is going to go.
  3. Record Accumulator It buffers all the records sent by Kafka template and these records only sent to the Kafka Topics when this buffer gets full.(However, linger.ms file is there where we can set the time limit)
Bibliology answered 1/9, 2022 at 11:59 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.