Kafka Template和Kafka生产者之间有什么区别?

huangapple go评论82阅读模式
英文:

What is the difference between Kafka Template and kafka producer?

问题

我看到 Kafka 模板在内部使用了 Kafka 生产者。我只想知道确切的区别是什么。
另外,我发现 Kafka 模板中有许多 send() 方法,与 Kafka 生产者相比。
如果有人知道更多信息,请帮我解答。

英文:

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.

答案1

得分: 9

生产者是一种模式,而KafkaTemplate则封装了一个Producer实例,并提供了方便的方法来将消息发送到Kafka主题。

Kafka生产者在Apache Kafka中进行了定义。KafkaTemplate是Spring对其的实现(尽管它并没有直接实现Producer),因此它提供了更多供您使用的方法。因此,您可以使用KafkaTemplate来入门,或者通过实现自己的Producer来实现您自己的解决方案。

英文:

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.

答案2

得分: 1

Kafka Producer 是 PubSub 模式中的生产者术语。
如果您想使用 Spring 实现 Apache Kafka,Spring 已经提供了一个包装器,我们称之为 Kafka Template
Kafka 模板 是 Spring 提供的一个类,用于将消息生产到 Kafka 主题
Kafka 模板的工作原理:
Kafka 模板在执行任务时涉及不同的层次 -

  1. 序列化器(SERIALIZER) 我们打算发送到 Kafka 主题的任何记录都需要序列化为字节。(涉及到 2 种技术 - a) key.serializer b) value.serializer)
  2. 分区器(Partitioner) 它确定消息将进入哪个分区。
  3. 记录累加器(Record Accumulator) 它缓冲 Kafka 模板发送的所有记录,只有当此缓冲区变满时,这些记录才会被发送到 Kafka 主题。(但是,还有 linger.ms 参数,可以设置时间限制)
英文:

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)

huangapple
  • 本文由 发表于 2020年9月9日 16:53:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/63808139.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定