千家信息网

关于Kafka的其他一些内容,堆积情况,retention,auto.offset.reset

发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,producer是线程安全的,多线程分享共用一个producer比用多个 producer整体上要快如果你想了解大数据的学习路线,想学习大数据知识以及需要免费的学习资料可以加群:784789432.欢
千家信息网最后更新 2026年11月02日关于Kafka的其他一些内容,堆积情况,retention,auto.offset.reset

producer是线程安全的,多线程分享共用一个producer比用多个 producer整体上要快

如果你想了解大数据的学习路线,想学习大数据知识以及需要免费的学习资料可以加群:784789432.欢迎你的加入。每天下午三点开直播分享基础知识,晚上20:00都会开直播给大家分享大数据项目实战。

可以命令行查看某consumer group所有consumer的offset,和落后的多少,也就是说可以查看Kafka中数据的堆积情况,以下来自官方文档

Sometimes it's useful to see the position of your consumers. We have a tool that will show the position of all consumers in a consumer group as well as how far behind the end of the log they are. To run this tool on a consumer group named my-group consuming a topic named my-topic would look like this:

bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group my-group

Note: This will only show information about consumers that use the Java consumer API (non-ZooKeeper-based consumers).

TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID
my-topic 0 2 4 2 consumer-1-029af89c-873c-4751-a720-cefd41a669d6 /127.0.0.1 consumer-1
my-topic 1 2 3 1 consumer-1-029af89c-873c-4751-a720-cefd41a669d6 /127.0.0.1 consumer-1
my-topic 2 2 3 1 consumer-2-42c1abd4-e3b2-425d-a8bb-e1ea49b29bb2 /127.0.0.1 consumer-2

This tool also works with ZooKeeper-based consumers:

bin/kafka-consumer-groups.sh --zookeeper localhost:2181 --describe --group my-group

Note: This will only show information about consumers that use ZooKeeper (not those using the Java consumer API).

TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID
my-topic 0 2 4 2 my-group_consumer-1
my-topic 1 2 3 1 my-group_consumer-1
my-topic 2 2 3 1 my-group_consumer-2

retention

Kafka保留消费后的数据,但也不是永远保留,默认7天后,会自动删除数据。当然我们可以设置保留(retention)几天,由broker config (也就是server.properties)中的log.retention.ms、log.retention.minutes、log.rentention.hours设置,优先级递增。默认log.rentention.hours=168。

还有一种retention的设置方法,就是log.retention.bytes,也是server.properties中设置,定义了一个partition存储的最大大小。两种方法一种满足就会删除。

kafka删除是按照segment来删,一次只能整个删掉一个或多个segment。

另外也可以设置每个topic的retention情况,具体看官方文档http://kafka.apache.org/documentation/

See http://kafka.apache.org/documentation/#brokerconfigs for the full list of log.retention./log.roll./log.segment.* configs

auto.offset.reset

What to do when there is no initial offset in Kafka or if the current offset does not exist any more on the server (e.g. because that data has been deleted):
earliest: automatically reset the offset to the earliest offset
latest: automatically reset the offset to the latest offset
none: throw exception to the consumer if no previous offset is found for the consumer's group
anything else: throw exception to the consumer.

default: latest

每一个topic记录offset,offset属于不同的group,一个group只有一个offset(每个partition)

数据 学习 情况 也就是 多个 官方 文档 方法 知识 线程 直播 不同 最大 安全 也就是说 优先级 只有 命令 基础 基础知识 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 蓝思科技飞鸽互联网 互联网科技有限公司图片 互联网金融 科技 猪兼强互联网科技 奇酷互联网科技 迪茉互联网科技 互联网科技logo设计 齐家互联网科技有限公司 互联网科技宣传片 深圳卡尔迅互联网科技有限公司怎么样 佩信高科技互联网 港股科技和互联网 中国科技创新与世界互联网大会 互联网在线教育科技创业 上海创道互联网络科技有限公司 本届互联网大会上的黑科技 版纳互联网科技选哪家 互联网科技创新方面的资料 银川新华互联网科技学校招聘 互联网 科技节活动 微视频大赛 A股互联网金融科技公司 工业互联网科技新基建 互联网科技卖菜 汉立互联网科技有限公司联系电话 恒生互联网科技指数跳水 健康食品互联网创新科技园项目 中和天地互联网科技有限公司 无锡工业互联网科技有限公司 高科技互联网套路 利用互联网等科技手段
0