kafka官方文档_kafka groupid

kafka官方文档_kafka groupid介绍Kafka是一个分布式的、分区的、冗余的日志提交服务。它使用了独特的设计,提供了所有消息传递系统所具有的功能。我们先来看下几个消息传递系统的术语:Kafka维护消息类别的东西是主题(topic).

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

介绍

Kafka是一个分布式的、分区的、冗余的日志提交服务。它使用了独特的设计,提供了所有消息传递系统所具有的功能。

我们先来看下几个消息传递系统的术语:

  • Kafka维护消息类别的东西是主题(topic).
  • 我们称发布消息到Kafka主题的进程叫生产者(producer).
  • 我们称订阅主题、获取消息的进程叫消费者(consumer).
  • Kafka是由多个服务器组成的机器,每个服务器称作代理(broker).

在较高的层次上看,生产者通过网络发送消息到Kafka集群,Kafka集群将这些消息提供给消费者,如下图:

53271bf2-1ca3-4577-a8b7-16d2a5b69e79

客户端与服务器之间的通信通过一个简单的、高性能的、语言无关的TCP protocol. Kafka有Java 客户端,但这客户端在很多语言many languages也是有效的.

主题(Topics)、日志(Logs)

一个主题就是消息的类别或名称。对每个主题,Kafka集群都管理着一个被分区的日志,如下:

1e47a1b0-93c1-4248-945d-72c033b232e5

每个分区就是一个提交日志:每个分区上保存着不断被追加的消息,这些消息是有序的且顺序不可改变;分区上的每个消息都被分配了一个序列号offset,offset唯一标识了分区上的消息。

Kafka集群保留所有发布的消息,不管这些消息是否被消费了,直到消息达到了它的存活周期,这个存活周期是可以被配置的。例如,日志被设置保留2天,消息被消费后还将继续存活,直到2天以后它才被删除释放。 数据的大小不会影响Kafka的性能,保留大量数据是没问题的(Kafka’s performance is effectively constant with respect to data size so retaining lots of data is not a problem)

事实上,在每个消费者上保留的元数据只有offset,它是消费者在日志上的位置。这个offset受消费者控制:正常情况下,随着消费者读取消息offset是线性增长的,但是消费者可以控制offset,消费者可以以任何顺序消费消息。例如,一个消费者可以重置到老的offset来从新执行。

这些特性表明,Kafka的消费者是非常廉价的,一个消费者的创建、销毁不会对集群或其他消费者产生多大的影响。

对日志进行分区有几个目的:

1、扩容,一个主题可以有多个分区,这使得可以保存比一个机器保存的多的多的数据。

2、并行。

分布式(Distribution)

日志的分区分布在Kafka集群的多台机器上,每个机器管理数据和响应分区请求。每个分区冗余存储来保证容错,冗余数可以配置。

每个分区都有一个机器作为leader,零个或多个机器作为follower。leader处理这个分区的读写请求,follower执行leader的指令。如果leader宕机了,followers中的一个将自动成为新的leader。每个机器都是它的分区的leader和其他分区的follower,follower角色用来负载均衡。

生产者(Producers)

生产者发布数据到它们选择的主题上。生产者负责将某条消息分配到某个主题的某个分区上。这可以通过简单的循环的方式来实现,或者使用一些分区方法(比如根据消息的key来分区)

消费者(Consumers)

传统的消息传递有两种方式: 队列(queuing)、发布-订阅(publish-subscribe). 队列方式,一组消费者从机器上读消息,每个消息只传递给这组消费者中的一个;分布-订阅方式,消息被广播到所有的消费者。 Kafka提供了一个消费组(consumer group)的说法来概括这两种方式。

消费者都有一个消费组,主题的每个消息被传递到订阅这个主题的消费组中的一个消费者实例,消费者实例可以是一个单独的进程或一个单独的机器。

如果所有的消费者在同一个组里,这就相当于队列方式,在消费者上的负载均衡。(If all the consumer instances have the same consumer group, then this works just like a traditional queue balancing load over the consumers.)

如果消费者在不同的组里,这就相当于发布-订阅方式,所有的消息将被广播到所有的消费者。(If all the consumer instances have different consumer groups, then this works like publish-subscribe and all messages are broadcast to all consumers.)

一般的情况是,主题有少量的消费组,每个消费组就是一个逻辑上的订阅者。每个消费组由很多消费者组成,有很好的扩展性和容错。. This is nothing more than publish-subscribe semantics where the subscriber is cluster of consumers instead of a single process.

4d5c6581-284f-4238-bb7c-ef1e470095a8
A two server Kafka cluster hosting four partitions (P0-P3) with two consumer groups. Consumer group A has two consumer instances and group B has four.

Kafka比传统的消息传递系统有更好的顺序行保证。

A traditional queue retains messages in-order on the server, and if multiple consumers consume from the queue then the server hands out messages in the order they are stored. However, although the server hands out messages in order, the messages are delivered asynchronously to consumers, so they may arrive out of order on different consumers. This effectively means the ordering of the messages is lost in the presence of parallel consumption. Messaging systems often work around this by having a notion of “exclusive consumer” that allows only one process to consume from a queue, but of course this means that there is no parallelism in processing.

Kafka does it better. By having a notion of parallelism—the partition—within the topics, Kafka is able to provide both ordering guarantees and load balancing over a pool of consumer processes. Kafka将主题下的分区分配给消费组里的消费者,每个分区被一个消费者消费,This is achieved by assigning the partitions in the topic to the consumers in the consumer group so that each partition is consumed by exactly one consumer in the group. By doing this we ensure that the consumer is the only reader of that partition and consumes the data in order. Since there are many partitions this still balances the load over many consumer instances. 消费者的数量不能超过分区数Note however that there cannot be more consumer instances than partitions.

Kafka只能保证分区内的消息是有序的 only provides a total order over messages within a partition, not between different partitions in a topic. Per-partition ordering combined with the ability to partition data by key is sufficient for most applications.如果你想要消息是全局有序的,你可以设置主题只有一个分区,同时这意味着只能有一个消费者。 However, if you require a total order over messages this can be achieved with a topic that has only one partition, though this will mean only one consumer process.

保证(Guarantees)

At a high-level Kafka gives the following guarantees:

  • 生产者发送的消息安装它们发送的顺序追加到主题
  • 消费者看到消息的顺序就是消息在日志中存储的顺序
  • For a topic with replication factor N, we will tolerate up to N-1 server failures without losing any messages committed to the log.

More details on these guarantees are given in the design section of the documentation.

来源: <http://kafka.apache.org/documentation.html#introduction>

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/166777.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • java 笛卡尔积_使用Guava来计算笛卡尔积

    java 笛卡尔积_使用Guava来计算笛卡尔积以前做项目的时候计算笛卡尔积的时候,总是使用各种for循环来嵌套,最后往往在Sonar代码检查的时候总是会报警说for循环嵌套过深。今天才知道Guava原来已经为我们提供了优雅的计算笛卡尔积的方法。比如我们要计算3个List的笛卡尔积,每个list的内容都是[‘a’,’b’,’c’],请看下面的代码:publicclassCartesianProductUtil{publicstat…

    2022年7月27日
    1
  • stringutil.isnotempty_中低腰和低腰的区别

    stringutil.isnotempty_中低腰和低腰的区别
    转自:http://www.zhenhua.org/article.asp?id=625
     
    isNotEmpty将空格也作为参数,isNotBlank则排除空格参数

    参考QuoteStringUtils方法的操作对象是java.lang.String类型的对象,是JDK提供的String类型操作方法的补充,并且是null安全的(即如果输入参数String为null则不会抛出NullPointerException,而是做了相应处理,例如,如果输入为

    2022年8月12日
    3
  • Python 常用string函数

    Python 常用string函数字符串中字符大小写的变换1.str.lower()//小写>>>'SkatE'.lower()'skat

    2021年12月24日
    45
  • sql 日期格式汇总

    sql 日期格式汇总

    2021年11月26日
    45
  • AutoreleasePool的那些事

    AutoreleasePool的那些事

    2021年6月6日
    128
  • Python 奇淫技巧 — 利用pandas读取xml转换为excel

    Python 奇淫技巧 — 利用pandas读取xml转换为excel因为工作需要,将xml中特定的节点值取出来,然后统计到excel中。于是乎试试写了一个python脚本,加快工作效率。而且今后还能复用。以下为完整示例,需要的朋友们可参考。示例XML<?xmlversion=”1.0″encoding=”utf-8″?><breakfast_menu><food><name>BelgianWaffles</name><price>$5.95

    2022年8月22日
    13

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号