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.
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.
KafkaTemplate
, @KafkaListener
- similar abstractions are available for RabbitMQ and JMS. It is a higher level abstraction. spring.io/projects/spring-kafka –
Kempe 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 -
- 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 )
- Partitioner It determines in which partition the message is going to go.
- 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)
© 2022 - 2025 — McMap. All rights reserved.