尧图网络 高端网站定制 · 原创设计
免费咨询热线
400-888-6620
免费获取方案
【初识-介绍】kafka基础(1):kafka introduction
通过官网我们可以知道kafka是一个事件流平台具有读写数据设置数据保存时常以及设定消费策略实时、重复消费的能力。kafka由server和client组成他们之间通过TCP进行通讯。kafka有生产者、消费者、topic、分区等主要概念其中分区实现了分区存储、容错性以及性能的提升。可以通过kafka 提供的api实现生产、消费、处理数据等功能。kafka一般用于缓存/消峰、解耦和异步通信等场景中。文章目录1. Apache Kafka® is an event streaming platform. What does that mean?2. How does Kafka work in a nutshell?3. Main Concepts and Terminologya. 事件b. 生产者和消费者c.事件的存储topic和kafka性能d. topic的分区4. kafka api5. 使用场景1. Apache Kafka® is an event streaming platform. What does that mean?kafka是一个事件流平台。kafka的三个能力发布(写)和订阅(读)事件流包括从其他系统不断地导入/导出数据。可以按照设定的数据保留时长来存储kafka数据可以实时的消费产生的数据或者重新消费已经产生的数据。Kafka combines three key capabilities so you can implement your use cases for event streaming end-to-end with a single battle-tested solution:To publish (write) and subscribe to (read) streams of events, including continuous import/export of your data from other systems.To store streams of events durably and reliably for as long as you want.To process streams of events as they occur or retrospectively.2. How does Kafka work in a nutshell?kafka是一个分布式系统由server和client组成两者通过TCP协议进行通讯。serverskafka集群可以运行一个或多个serverserver之间可以跨多个数据中心或云区域。其中组成存储层的servers称为brokerkafka具有高拓展性和容错性即当任何server故障时其他的server将会接管它们的工作确保在连续的操作下不丢失数据。clientclient允许通过编写分布式应用或微服务实现并行、大规模以及容错的方式处理读、写、处理流数据甚至在网络问题或机器故障的情况下。Kafka is a distributed system consisting of servers and clients that communicate via a high-performance TCP network protocol.Servers: Kafka is run as a cluster of one or more servers that can span multiple datacenters or cloud regions. Some of these servers form the storage layer, called the brokers. Other servers run Kafka Connect to continuously import and export data as event streams to integrate Kafka with your existing systems such as relational databases as well as other Kafka clusters. To let you implement mission-critical use cases, a Kafka cluster is highly scalable and fault-tolerant: if any of its servers fails, the other servers will take over their work to ensure continuous operations without any data loss.Clients: They allow you to write distributed applications and microservices that read, write, and process streams of events in parallel,at scale,and in a fault-tolerant manner even in the case of network problems or machine failures.3. Main Concepts and Terminologya. 事件事件是记录的已经发生过的一些事情也可以称为record或message。概念上来说一个事件包含keyvalue时间戳和可选择性的元数据头。见下面的例子Event key: “Alice”Event value: “Made a payment of $200 to Bob” Event timestamp: “Jun. 25, 2020 at 2:06 p.m.”b. 生产者和消费者生产者是那些将事件写发布到kafka的应用消费者订阅读和处理那些数据。在kafka中两者是完全解耦和与彼此无关的这是kafka高拓展性的关键。例如生产者从不等消费者。kafka提供了许多像exactly-once处理数据的能力。c.事件的存储topic和kafka性能event被组织和持久化在topic中。 简单的说一个topic类似于一个文件夹events是文件夹中的文件。例如账单。topic对应多个消费者或生产者topic中一般都会有多个producer和subscriber即一个主题可以有0个、1个或多个生产者向其写入事件以及0个、1个或多个消费者订阅这些事件。反复消费与保留时间事件可以根据需要随时读取与传统消息传递系统不同事件在使用后不会被删除。不过你可以设定每一个topic在kafka中的保留时间。与数据量无关的性能kakfa的性能和存储的数据量没有关系所以长时间的存储数据也可以保持良好的性能。d. topic的分区分区与并发topic被分区意味着一个topic会散布在不同brokers中的buckets里。这种数据的分布式放置对于伸缩性很重要因为它允许客户端的应用程序可以同时从多个broker中读写数据。多少分区就可以有多少并发根据event的key写入不同的分区与只读指定的分区一条新的数据写到topic中时其实只是添加到了topic中的一个分区。具体地具有相同event key的event(例如客户或车辆id)会写到相同的分区。kafka保证给定topic-partition的消费者始终读取该分区的event并且它们写入的顺序相同。When a new event is published to a topic, it is actually appended to one of the topic’s partitions. Events with the same event key (e.g., a customer or vehicle ID) are written to the same partition, and Kafka guarantees that any consumer of a given topic-partition will always read that partition’s events in exactly the same order as they were written.看一个例子这个topic有四个分区。两个不同的分区互相独立发布新events到topic分区。相同的event-key将会写到相同的分区。其中如果合适的话两个生产者可以写到一个分区中。Note that both producers can write to the same partition if appropriate.分区的容错性为了保证数据的容错和高可用每一个topic可以备份即使是跨地理区域或数据中心的。 有多个broker拥有数据的副本以防出错。常见的生产设置将复制因子设置为3。这种复制是在topic-partition级别执行的。To make your data fault-tolerant and highly-available, every topic can be replicated, even across geo-regions or datacenters, so that there are always multiple brokers that have a copy of the data just in case things go wrong, you want to do maintenance on the brokers, and so on. A common production setting is a replication factor of 3, i.e., there will always be three copies of your data. This replication is performed at the level of topic-partitions.4. kafka apiKafka有5个用于Java和Scala的核心api:Admin API 管理和检查topic、brokers、和其它kafka对象Producer API发布流事件到一个或者多个kafka主题。Consumer API订阅一个或多个主题并处理产生于这些主题的流事件Kafka Streams API实现流处理应用和微服务。提供更高一层的函数去处理流事件包括转换有状态的例如聚合和join操作window基于事件时间处理等等。 从一个或多个topics读取数据并输出结果到一个或多个topic。Kafka Connect API构建并运行可重用的数据导入导出连接器。这些连接器读写来自外部系统和应用程序的事件流以便和kafka进行集成。The Admin API to manage and inspect topics, brokers, and other Kafka objects.The Producer API to publish (write) a stream of events to one or more Kafka topics.The Consumer API to subscribe to (read) one or more topics and to process the stream of events produced to them.The Kafka Streams API to implement stream processing applications and microservices. It provides higher-level functions to process event streams, including transformations, stateful operations like aggregations and joins, windowing, processing based on event-time, and more. Input is read from one or more topics in order to generate output to one or more topics, effectively transforming the input streams to output streams.The Kafka Connect API to build and run reusable data import/export connectors that consume (read) or produce (write) streams of events from and to external systems and applications so they can integrate with Kafka.5. 使用场景缓冲和消峰有助于控制和优化数据流经过系统的速度解决生产消息和消费消息的处理速度不一致的情况。解耦允许独立的扩展或修改两边的处理过程只要确保它们遵守同样的接口约束。异步通信允许用户把一个消息放入队列但并不立即处理它然后在需要的时候再去处理它们。
RELATED

相关推荐

【配置/认证】Authentication for Hadoop(3.3.1) HTTP web-consoles : Hadoop的simple认证 不是银弹

【配置/认证】Authentication for Hadoop(3.3.1) HTTP web-consoles : Hadoop的simple认证 不是银弹

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

📅 2026/11/3 1:10:34
shell基础(1):shell概述、第一个shell脚本、shell怎么执行、怎么判断bash的内部命令

shell基础(1):shell概述、第一个shell脚本、shell怎么执行、怎么判断bash的内部命令

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

📅 2026/11/3 1:10:34
Luxand FaceSDK的8.0和8.1和8.2和8.3和9.0.1序列号

Luxand FaceSDK的8.0和8.1和8.2和8.3和9.0.1序列号

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

📅 2026/11/3 1:10:34
MORE NEWS

更多资讯

📰

解决ColabFold部署中的JAX版本冲突问题

1. 问题背景与核心痛点最近在本地环境部署ColabFold时遇到了JAX版本冲突问题,这其实是生物信息学工具链中一个相当典型的依赖管理难题。ColabFold作为AlphaFold2的高效替代方案,其核心计算依赖于JAX这个高性能数值计算库。但JAX的版本迭代速度极快&#…

📰

渗透测试必备搜索引擎工具集与实战技巧

1. 项目概述作为一名长期从事网络安全领域的技术从业者,我深知在渗透测试和信息收集阶段,选择合适的搜索引擎工具往往能事半功倍。今天要分享的这份精选搜索引擎列表,是我在过去五年实战中逐步积累和验证的核心工具集,涵盖了从常规…

📰

Java+SpringBoot构建冷链物流生鲜销售系统实践

1. 项目概述:冷链运输生鲜销售系统的核心价值冷链物流生鲜销售平台是当前生鲜电商和食品供应链数字化转型的关键基础设施。这个基于Java技术栈开发的系统,解决了从产地到餐桌全流程的温控管理、库存周转和订单协同问题。我在实际部署中发现,传…

📰

基于DSP28335与AD2S1210的SPI角度读取实战

简介:面向电机控制方向初学者与嵌入式开发者的DSP28335与AD2S1210旋变解码配置资料,聚焦入职初期如何通过SPIA模块完成高精度位置信息采集这一实际问题。内容围绕SPI接口初始化展开,涵盖时钟极性与相位设置、波特率配置、SPI收发函数编写&…

📰

程序员必备1800词汇:突破英文技术文档阅读障碍

简介:这份资源是一份面向程序员群体的计算机英语词汇手册,覆盖前端与后端开发场景,适合从编程初学者到进阶开发者用来补齐技术英语短板。内容围绕约1800个开发常用词汇展开,每个词条配有音标与中文注释,并收录了access…

📰

SolidWorks二次开发入门:宏录制、API读写与避坑指南

简介:这是一份面向SolidWorks二次开发初学者与希望提升自动化建模效率的工程师的系统教程文档,围绕API与VBA宏展开,重点解决从录制宏到编辑、调试与精简代码的入门问题。压缩包内共1个doc文件,大小约276KB,以图文教程形…

TODAY

今日更新

THIS WEEK

本周精选

THIS MONTH

本月热门

读完文章,想聊聊您的网站?

告诉我们您的行业与需求,资深顾问一对一梳理方案与报价,全程免费。

📞 💬