apache kafka_Apache Kafka简介

2023-11-17

apache kafka

During the last years, technologies for building real-time data pipelines and event streaming apps have emerged, promoting also the horizontal scalability and the fault tolerance of a system. One of these technologies is Apache Kafka.

在过去的几年中,用于构建实时数据管道和事件流应用程序的技术应运而生,这也促进了系统的水平可扩展性和容错能力。 这些技术之一是Apache Kafka

介绍 (Introduction)

Apache Kafka is an open-source distributed streaming platform developed initially by LinkedIn and donated to the Apache Software Foundation. The project, written in Scala and Java, aims to provide a unified, high-throughput, low-latency platform for handling real-time data feeds. By definition, a streaming platform has 3 key capabilities :

Apache Kafka是一个开放源代码的分布式流媒体平台,最初由LinkedIn开发,并捐赠给Apache Software Foundation。 该项目以ScalaJava编写,旨在提供一个统一的,高吞吐量,低延迟的平台来处理实时数据馈送。 根据定义,流媒体平台具有3个关键功能:

  • Publish and subscribe to streams of records, similar to a message queue or enterprise messaging system

    发布和订阅记录流,类似于消息队列或企业消息传递系统
  • Store streams of records in a fault-tolerant durable way

    以容错的持久方式存储记录流
  • Process streams of records as they occur

    处理记录流

In general, Kafka is used to building real-time event streaming applications. To understand how Kafka works, let’s see some basic concepts :

通常,Kafka用于构建实时事件流应用程序。 为了了解Kafka的工作原理,让我们看一些基本概念:

  • Kafka is run as a cluster on one or more servers that can span multiple datacenters

    Kafka在一个或多个可以跨越多个数据中心的服务器上作为集群运行

  • the Kafka cluster stores stream of records in categories called topics

    Kafka集群将记录流存储在称为主题的类别中

  • each record consists of a key, a value, and a timestamp

    每个记录由一个键,一个值和一个时间戳组成

Kafka has 5 core APIs to interact with topics :

Kafka有5个核心API与主题进行交互:

  • Producer API : allows to publish a stream of records to one or more topics

    生产者API :允许将记录流发布到一个或多个主题

  • Consumer API : allows to subscribe to one or more topics and process the stream of records produced to them

    消费者API :允许订阅一个或多个主题并处理为其生成的记录流

  • Streams API : allows to act as a stream processor, consuming an input stream from one or more topics and producing an output stream to one or more output topics, effectively transforming the input streams to output streams

    Streams API :允许充当流处理器,使用一个或多个主题的输入流,并生成一个或多个输出主题的输出流,从而有效地将输入流转换为输出流

  • Connector API : allows building and running reusable producers or consumers that connect Kafka topics to existing applications or data systems (e.g. to a relational database capturing every change to a table)

    连接器API :允许建立和运行可重用的生产者或使用者,以将Kafka主题连接到现有应用程序或数据系统(例如,关系数据库,以捕获对表的所有更改)

  • Admin API : allows managing and inspecting topics, brokers and other Kafka objects

    Admin API :允许管理和检查主题,代理和其他Kafka对象

主题,分区和偏移 (Topics, Partitions and Offsets)

A topic is a stream of records and represents a category or a feed name to which records are published at cluster level. It is always multi-subscriber, in the sense that it can have zero, one or more consumers subscribing and listening to the data written to it. A topic is split into partitions.

主题是记录的流,表示在群集级别将记录发布到的类别或订阅源名称。 从它可以有零个意义上说,它始终是多用户,一个或多个消费者订阅并侦听写入其中的数据。 主题分为多个分区。

Each partition is ordered and messages are consumed in the arrival order (FIFO — first in, first out). Each message getting published to a topic partition gets an incremental id, called offset.

每个分区都有序,消息按到达顺序使用(FIFO-先进先出)。 每个发布到主题分区的消息都获得一个增量ID,称为offset

Other significant information:

其他重要信息:

  • Offsets only have meaning inside a specific partition of the topic

    偏移仅在主题的特定分区内具有含义
  • The data written to a partition can’t be changed and it is kept only for a limited time (topics have a phyisical structure similar to logs)

    写入分区的数据无法更改,只能保留有限的时间(主题的物理结构类似于日志)
  • Order is guaranteed only within a partition

    仅在分区内保证订单

生产者和消费者 (Producers and Consumers)

Producers publish data to the topics of their choice. A producer is responsible for choosing which record to assign to which partition within the topic : this can be done in a round-robin fashion or according to a specific given function, based on the key of the record.

生产者将数据发布到他们选择的主题。 生产者负责选择将哪个记录分配给主题中的哪个分区:可以基于记录的密钥以循环方式或根据给定的特定功能来完成。

A key of a record can be of any kind (string, number) and must be specified to send the data to the specific partition (assigned to that key). If the key is null, the data is sent in round-robin way, but if the key is not null then all the messages for that key will go to the same partition.

记录的可以是任何类型(字符串,数字),并且必须指定该键才能将数据发送到特定分区(分配给该键)。 如果密钥为null,则以循环方式发送数据,但是如果密钥不为null,则该密钥的所有消息都将进入同一分区。

Consumers read data from a topic, labeling themselves with a consumer group name. This is a particular concept which guarantees that a consumer within a group reads from exclusive partitions (i.e. a consumer gets assigned to one partition). If you have more consumers than partitions, some consumers will be idle.

消费者从主题中读取数据,并用消费者组名称标记自己。 这是一个特殊的概念,可确保组中的使用者从互斥分区读取(即,将使用者分配到一个分区)。 如果您的使用者数量大于分区数量,则某些使用者将处于空闲状态。

Consumer Offsets is the offset concepts for the consuming side. Kafka stores the offset at which a consumer group has arrived to read so that if a consumer within a specific consumer group dies, another consumer in the consumer group will be able to read back from where the dead consumer left off. Consumer offsets are stored in an internal Kafka topics called __consumer_offsets. The offset must be committed each time a single consumer has finished to consume the message : in this way, the message is no more available to that consumer group unless the offset is reset to the starting or a specific offset.

消费者抵销是消费方的抵销概念。 Kafka存储了一个消费组已到达要读取的偏移量,因此,如果特定消费组内的某个消费者死亡,则该消费组中的另一个消费者将能够从死去的消费者停止的地方进行读取。 使用者偏移量存储在内部__fums_offsets的 Kafka主题中。 每当单个使用者结束使用该消息时,就必须提交偏移量:这样,除非该偏移量重置为起始偏移量或特定偏移量,否则该消息对该使用者组不再可用。

Other consumers information to keep in mind :

其他消费者要记住的信息:

  • consumers know which broker to read from and if one broker fails, they know how to failover

    消费者知道从哪个代理读取,并且如果一个代理发生故障,他们就会知道如何进行故障转移
  • a consumer reading data from one partition make it with the same order of the publishing of the records

    消费者从一个分区中读取数据,使其具有与记录发布相同的顺序
  • there is no guarantee across the order between two partitions of the same topic

    不能保证同一主题的两个分区之间的顺序一致

Another important concept for the consuming is the Delivery Semantics. Kafka provides 3 delivery semantics for consumers :

消费的另一个重要概念是交付语义 。 Kafka为消费者提供3种交付语义:

  • At most once: offsets are committed as soon as the message is received. If the processing goes wrong, the message will be lost

    最多一次 :收到消息后立即提交偏移量。 如果处理出错,该消息将丢失

  • At least once (usually): offsets are committed after the message is processed. If the processing goes wrong, the message will be read again

    至少一次 (通常):在处理消息后提交偏移量。 如果处理出错,将再次读取该消息

  • Exactly once: it can be achieved for Kafka to Kafka workflows using Kafka Streams API. For Kafka to External System workflows use an idempotent consumer

    一次 :可以使用Kafka Streams API从Kafka到Kafka工作流程来实现。 对于从Kafka到外部系统的工作流程,请使用幂等的使用者

ZooKeeper,集群和经纪人 (ZooKeeper, Cluster and Brokers)

Until this point, we have said that Kafka brokers are in a cluster, but how this cluster is managed? Kafka relies on Apache Zookeeper to manage their brokers. Let’s see the main ZooKeeper characteristics :

在此之前,我们已经说过Kafka经纪人在一个集群中,但是如何管理这个集群? Kafka依靠Apache Zookeeper来管理其代理。 让我们看看ZooKeeper的主要特征:

  • it helps performing leader election for partitions

    它有助于执行分区的领导者选举
  • it sends notifications to Kafka in case of changes

    如果发生更改,它将向Kafka发送通知
  • it must be run before a Kafka server starts

    它必须在Kafka服务器启动之前运行
  • by design, it operates with an odd number of servers

    根据设计,它可以在奇数个服务器上运行
  • it has a leader, which handle the writes from the brokers, while the rest of the servers are the followers (handling only reads)

    它有一个领导者,负责处理来自代理的写操作,而其余服务器则是跟随者(仅处理读操作)
  • it doesn’t store consumer offsets, instead they are stored in an internal Kafka topic (as we said previously)

    它不存储消费者偏移量,而是存储在内部Kafka主题中(如我们之前所述)

A Kafka broker is a server inside a cluster. Each broker is identified with an integer ID and when you connect to any broker of the cluster, you get connected to the entire cluster. Each broker can contains certain topic partitions, with some kind of data but not necessarily all the data of the topic. Brokers are stateless, then it is ZooKeeper that maintains the cluster state. A good number of brokers for a cluster is 3.

Kafka代理是群集中的服务器。 每个代理都用一个整数ID标识,当您连接到集群的任何代理时,您就可以连接到整个集群。 每个代理可以包含某些主题分区,其中包含某种数据,但不一定包含该主题的所有数据。 代理是无状态的,然后是ZooKeeper维护集群状态。 集群的大量代理为3。

A broker can subscribe in ZooKeeper to the “/brokers/ids” path where all brokers are registered so that they can be notified when other brokers are added or removed. Starting another broker with the same ID will produce an error, then the broker won’t start. Even though the node representing the broker is gone when the broker is stopped, the broker ID still exists in other data structures; this way, if you completely lose a broker and start a new broker with the ID of the old one, it will immediately join the cluster in place of the missing broker with the same partitions and topics assigned to it. The first broker that starts in the cluster becomes the controller, responsible for electing partition leaders; the following brokers will receive a “node already exists” exception.

经纪人可以在ZooKeeper中订阅所有经纪人都注册到的“ / brokers / ids”路径,以便在添加或删除其他经纪人时可以通知他们。 启动具有相同ID的另一个代理将产生错误,然后该代理将无法启动。 即使停止代理程序时代表代理程序的节点不见了,代理程序ID仍存在于其他数据结构中。 这样,如果您完全丢失了一个代理,并使用旧ID来启动一个新的代理,它将立即加入群集,以代替丢失的具有相同分区和主题的代理。 在集群中启动的第一个代理将成为控制者,负责选举分区负责人。 以下代理将收到“节点已存在”异常。

经纪人发现 (Broker Discovery)

Every Kafka broker is also called a “bootstrap server” : this means you only need to connect to one broker and you will be connected to the entire cluster, because each broker knows all the information about the others. A list of Kafka servers is passed to the bootstrap-server parameter for the consumer instantiation and even though only one broker is needed, the consumer client will learn about the other broker from just one server. Usually, you list multiple brokers in case there is an outage so that the client can connect.

每个Kafka代理也称为“引导服务器”:这意味着您只需要连接到一个代理,就可以连接到整个集群,因为每个代理都知道有关其他代理的所有信息。 Kafka服务器列表将传递给bootstrap-server参数以进行消费者实例化,即使只需要一个代理,消费者客户端也将从一台服务器中了解其他代理。 通常,您列出多个代理以防万一发生故障,以便客户端可以连接。

结论 (Conclusion)

Well, these were the very basic notions of Apache Kafka. We’ve done a little introduction to the main Kafka API, we have defined what topics, partitions and offsets are, and we have seen how it works producing and consuming data on topic. Finally, we’ve seen how is managed the cluster of brokers in Kafka.

嗯,这些是Apache Kafka的非常基本的概念。 我们已经对主要的Kafka API进行了一些介绍,定义了主题,分区和偏移量,并了解了它如何工作并生成和使用主题数据。 最后,我们已经了解了如何在Kafka中管理经纪人集群。

This is the very starting point for Apache Kafka, because there are many other notions, as fault-tolerance and topic distribution and replication, and many other features you can use with Kafka, as Stream Processing and Connect API. I hope this article gives you the hint to learn Apache Kafka in depth, because it is one of most interesting technology that we have nowadays and it is used too much in the enterprise industry.

这是Apache Kafka的起点,因为还有许多其他概念,例如容错,主题分发和复制,以及可以与Kafka一起使用的许多其他功能,例如Stream Processing和Connect API。 我希望本文能为您提供深入学习Apache Kafka的提示,因为它是当今我们拥有的最有趣的技术之一,并且在企业行业中使用过多。

翻译自: https://medium.com/javarevisited/a-brief-introduction-to-apache-kafka-25a4ab386f4b

apache kafka

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

apache kafka_Apache Kafka简介 的相关文章

随机推荐

  • JavaWeb知识梳理(后端部分)

    JavaWeb 静态web资源 如html 页面 指web页面中供人们浏览的数据始终是不变 动态web资源 指web页面中供人们浏览的数据是由程序产生的 不同时间点访问web页面看到的内容各不相同 静态web资源开发技术 HTML CSS
  • mysql存储过程之传递参数

    in 表示传入的参数 in 参数名1 参数类型 in 参数名2 参数类型 delimiter create procedure func in id int begin select from 表 where Id id 查询Id id的信
  • Causal Attention for Vision-Language Tasks Paper: Causal Attention for Vision-Language Tasks个人理解

    Causal Attention for Vision Language Tasks Paper Causal Attention for Vision Language Tasks 传统的视觉语言任务中 如果数据集是长尾分布的 atten
  • 研发效能提升工具插件

    一 代码工具插件 GitHub Copilot https copilot github com GitHub Copilot 是一个基于OpenAI Codex的代码生成器 作为Visual Studio Code VSCode 的扩展提
  • c语言中+ =和=+有什么区别

    点击上方蓝字关注我 了解更多咨询 c语言中 和 有什么区别 区别在于 是简写 a 1就是a a 1 并不是简写 a a直接对a的赋值 符号代表的是正负 完全可以省略不写 即a b其实就是a b 在用C 编程时 我经常混淆 和 前者实际上是我
  • 高度封装的前后端框架-odoo回顾(四):翻译官方教程<<高级B:ACL和记录规则>>

    Advanced B ACL and Record Rules 高级B ACL和记录规则 Warning 警告 This tutorial assumes you have completed the Core Training 这个教程默
  • 集成学习与深度学习 加载模型方法

    1 集成学习 import joblib joblib load model pkl 2 深度学习 用torch自带的load import torch data torch load model pkl error pickle Unpi
  • JDK8 字节码操作

    java字节码技术 1 BCEL 基于汇编 2 ASM 轻量级 3 javassist 性能比发射高 比asm低 使用简单 4 cglib 基于ASM 应用场景 1 动态修改class文件 对类进行增删改 2 aop技术 3 lombok
  • 树、森林与二叉树相互转化

    1 树转换为二叉树 由于二叉树是有序的 为了避免混淆 对于无序树 我们约定树中的每个结点的孩子结点按从左到右的顺序进行编号 将树转换成二叉树的步骤是 1 加线 就是在所有兄弟结点之间加一条连线 2 抹线 就是对树中的每个结点 只保留他与第一
  • 《数字图像处理》学习总结及感悟:第二章数字图像基础(5)数学工具

    前往老猿Python博文目录 https blog csdn net LaoYuanPython 一 引言 本系列文章记录老猿自学冈萨雷斯 数字图像处理 的感悟和总结 不过估计更新会比较慢 白天要工作 都是晚上抽空学习 学习完一章再回头总结
  • 不小心删除了网络适配器中的无线网卡驱动?

    昨天电脑蓝屏了几次 查了下问题 有人说把win10的网卡重新安装下就好了 结果 我直接把网络适配器的无线网卡驱动给卸载了 就是这个样子 点击卸载后 网络适配器下面没有无线网卡的驱动 电脑也连不了网 还没有网线 驱动精灵就是垃圾 它没有适配我
  • 校招高频必背考点

    2 操作系统 2 1 基础 进程与线程的本质区别 以及各自的使用场景 进程是操作系统资源分配的基本单位 线程是操作系统调度的最小单位 一个进程可以中可以有多个线程 线程依赖于进程存在 进程状态 阻塞 就绪 运行 进程调度算法的特点以及使用场
  • 【分析笔记】全志 T507 PF4 引脚无法被正常设置为中断模式的问题分析

    相关信息 硬件平台 全志T507 系统版本 Android 10 Linux 4 9 170 问题描述 PF4 无法通过标准接口设置为中断模式 而 PF1 PF2 PF3 PF5 正常可用 分析过程 一开始以为是引脚被其它驱动占用引起 或者
  • vue路由配置

    import Vue from vue import Router from vue router Vue use Router Note 路由配置项 hidden true 当设置 true 的时候该路由不会再侧边栏出现 如401 log
  • flutter项目中 advance_image_picker 组件使用

    一 说明 Advance image picker 是flutter 插件 用于从Android 和 ios 图像库中选择多张图片 使用相机拍摄新照片 并对其进行编辑 下图为最终效果 这里有个bug 在连续多测按 旋转摄像头时 程序会出现卡
  • 关于TypeError:xxx() missing 1 required positional argument: ‘S‘问题处理意见

    关于TypeError xxx missing 1 required positional argument S 问题处理意见 关于调用python模块的方法总结 在调用自己保存的模块 py文件时 导入后就直接进行 文件名 函数进行调用 会
  • 查询手机所在地理位置的简单方法

    有时候坐在长途汽车或火车上 想知道现在到什么地方了 可以通过手机来简单定位 对于没有GPS功能的手机 要想知道当前所在地理位置 可以通过基站定位 具体有以下几种方法 1 直接查看基站编号 使用某些手机的工程模式 或者利用专门的软件 比如S6
  • Java中new Date().getTime()时间戳问题

    1 getTime 返回值 Java和JavaScript都支持时间类型Date 他们的getTime 方法返回的是毫秒数 默认返回的是13位数字 单位是毫秒 2 注意事项 Returns the number of millisecond
  • 无线 连接公司服务器,客户端无线连接服务器

    客户端无线连接服务器 内容精选 换一换 您可以在弹性负载均衡服务中创建一个负载均衡器 该负载均衡器会接收来自客户端的请求 并将请求转发到一个或多个可用区的后端服务器中进行处理 请求的流量分发与负载均衡器配置的分配策略类型相关 共享型和独享型
  • apache kafka_Apache Kafka简介

    apache kafka During the last years technologies for building real time data pipelines and event streaming apps have emer