文章目录

  • 1.概述

1.概述

防丢失

作者:半兽人
链接:https://www.orchome.com/35
来源:OrcHome
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

检查消费者的位置(Checking consumer position)
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:
有时候需要去查看你的消费者的位置。我们有一个显示【消费者组中】所有消费者的位置的工具。显示日志其落后多远。消费者组名为my-group,消费者topic名为my-topic,如下:

> bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zkconnect localhost:2181 --group testGroup           Topic                          Pid Offset          logSize         Lag             Owner
my-group        my-topic                       0   0               0               0               test_jkreps-mn-1394154511599-60744496-0
my-group        my-topic                       1   0               0               0               test_jkreps-mn-1394154521217-1a0be913-0
Copy

NOTE: Since 0.9.0.0, the kafka.tools.ConsumerOffsetChecker tool has been deprecated. You should use the kafka.admin.ConsumerGroupCommand (or the bin/kafka-consumer-groups.sh script) to manage consumer groups, including consumers created with the new consumer API.
注意:在0.9.0.0,kafka.tools.ConsumerOffsetChecker已经不支持了。你应该使用kafka.admin.ConsumerGroupCommand 或 bin/kafka-consumer-groups.sh脚本来管理消费者组,包括用新消费者API创建的消费者。

## 0.9+
bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server localhost:9092 --describe --group test-consumer-group## 0.10+
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group my-group

Copy
Managing Consumer Groups(管理消费者组)
With the ConsumerGroupCommand tool, we can list, describe, or delete consumer groups. Note that deletion is only available when the group metadata is stored in ZooKeeper. When using the new consumer API (where the broker handles coordination of partition handling and rebalance), the group is deleted when the last committed offset for that group expires. For example, to list all consumer groups across all topics:
用ConsumerGroupCommand工具,我们可以使用list,describe,或delete消费者组(注意,删除只有在分组元数据存储在zookeeper的才可用)。当使用新消费者API(broker协调处理分区和重新平衡),当该组的最后一个提交的偏移到期时,该组被删除。 例如,要列出所有主题中的所有用户组:

> bin/kafka-consumer-groups.sh --bootstrap-server broker1:9092 --listtest-consumer-group

Copy
To view offsets as in the previous example with the ConsumerOffsetChecker, we “describe” the consumer group like this:
要使用ConsumerOffsetChecker查看上一个示例中消费者组的偏移量,我们按如下所示“describe”消费者组:

> bin/kafka-consumer-groups.sh --bootstrap-server broker1:9092 --describe --group test-consumer-groupGROUP                          TOPIC                          PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG             OWNER
test-consumer-group            test-foo                       0          1               3               2               consumer-1_/127.0.0.1

Copy
There are a number of additional “describe” options that can be used to provide more detailed information about a consumer group:
还有一切其他的命令可以提供消费组更多详细信息:

-members: This option provides the list of all active members in the consumer group.
-members: 此选项提供使用者组中所有活动成员的列表。

> bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group my-group --membersCONSUMER-ID                                    HOST            CLIENT-ID       #PARTITIONS
consumer1-3fc8d6f1-581a-4472-bdf3-3515b4aee8c1 /127.0.0.1      consumer1       2
consumer4-117fe4d3-c6c1-4178-8ee9-eb4a3954bee0 /127.0.0.1      consumer4       1
consumer2-e76ea8c3-5d30-4299-9005-47eb41f3d3c4 /127.0.0.1      consumer2       3
consumer3-ecea43e4-1f01-479f-8349-f9130b75d8ee /127.0.0.1      consumer3       0

Copy
–members --verbose: On top of the information reported by the “–members” options above, this option also provides the partitions assigned to each member.
除了“–members”展示信息之外,此选项还展示分配给每个成员的分区。

> bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group my-group --members --verboseCONSUMER-ID                                    HOST            CLIENT-ID       #PARTITIONS     ASSIGNMENT
consumer1-3fc8d6f1-581a-4472-bdf3-3515b4aee8c1 /127.0.0.1      consumer1       2               topic1(0), topic2(0)
consumer4-117fe4d3-c6c1-4178-8ee9-eb4a3954bee0 /127.0.0.1      consumer4       1               topic3(2)
consumer2-e76ea8c3-5d30-4299-9005-47eb41f3d3c4 /127.0.0.1      consumer2       3               topic2(1), topic3(0,1)
consumer3-ecea43e4-1f01-479f-8349-f9130b75d8ee /127.0.0.1      consumer3       0               -

Copy
–offsets: This is the default describe option and provides the same output as the “–describe” option.
–offsets:默认的describe选项,与“–describe”选项相同的输出。

–state: This option provides useful group-level information.
–state:此选项提供有用的组级别信息

> bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group my-group --stateCOORDINATOR (ID)          ASSIGNMENT-STRATEGY       STATE                #MEMBERS
localhost:9092 (0)        range                     Stable               4
Copy

To manually delete one or multiple consumer groups, the “–delete” option can be used:
要手动删除一个或多个消费者组,可以使用“–delete”:

> bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --delete --group my-group --group my-other-groupDeletion of requested consumer groups ('my-group', 'my-other-group') was successful.
Copy

To reset offsets of a consumer group, “–reset-offsets” option can be used. This option supports one consumer group at the time. It requires defining following scopes: --all-topics or --topic. One scope must be selected, unless you use ‘–from-file’ scenario. Also, first make sure that the consumer instances are inactive. See KIP-122 for more details.
要重置消费者组的offset,可以使用“–reset-offsets”选项。此选项同一时间只支持一个消费者组操作。它需要定义以下范围:–all-topics 或 --topic。 除非您使用"–from-file"方案,否则必须选择一个范围。另外,首先请确保消费者实例处于非活动状态。有关更多详细信息,请参见KIP-122。

It has 3 execution options:
它有3个执行操作命令选项:

(default) to display which offsets to reset.
显示要重置的offset
–execute : to execute --reset-offsets process.
执行–reset-offsets处理
–export : to export the results to a CSV format.
–export:将结果导出为CSV格式。
–reset-offsets also has following scenarios to choose from (atleast one scenario must be selected):
–reset-offsets 还具有以下场景可供选择(必须选择至少一个场景):

–to-datetime : Reset offsets to offsets from datetime. Format: ‘YYYY-MM-DDTHH:mm:SS.sss’
–reset-offsets :将offset重置为与日期时间的offset。 格式:‘YYYY-MM-DDTHH:mm:SS.sss’

–to-earliest : Reset offsets to earliest offset.
–to-earliest : 将offset重置为最早的offset。

–to-latest : Reset offsets to latest offset.
–to-latest : 将offsets重置为最新的offsets。
–shift-by : Reset offsets shifting current offset by ‘n’, where ‘n’ can be positive or negative.
–shift-by : 重置offsets,通过移位“n”,其中“ n”可以为正或负。
–from-file : Reset offsets to values defined in CSV file.

  • –from-file : 将offset重置为CSV文件中定义的值。
    –to-current : Resets offsets to current offset.
    –to-current : 将offset重置为当前的offset。
    –by-duration : Reset offsets to offset by duration from current timestamp. Format: ‘PnDTnHnMnS’
    –by-duration : 将offset重置为从当前时间戳重置为持续时间offset。格式:“ PnDTnHnMnS”
    –to-offset : Reset offsets to a specific offset.
    –to-offset : 将offset重置为指定的。
    Please note, that out of range offsets will be adjusted to available offset end. For example, if offset end is at 10 and offset shift request is of 15, then, offset at 10 will actually be selected.
    请注意,超出范围的offset将调整为可用的offset。例如,如果offset最大为10,设置为15时,则实际上将选择offset将为10。

For example, to reset offsets of a consumer group to the latest offset:
例如,要将消费者组的offset重置为最新的offset:

> bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --reset-offsets --group consumergroup1 --topic topic1 --to-latestTOPIC                          PARTITION  NEW-OFFSET
topic1                         0          0

If you are using the old high-level consumer and storing the group metadata in ZooKeeper (i.e. offsets.storage=zookeeper), pass --zookeeper instead of bootstrap-server:
如果你使用是老的高级消费者并在zookeeper存储消费者组的元数据(即。offsets.storage=zookeeper),则通过–zookeeper,而不是bootstrap-server

> bin/kafka-consumer-groups.sh --zookeeper localhost:2181 --list

【Kafka】kafka检查消费者位置相关推荐

  1. 深入分析Kafka生产者和消费者

    深入Kafka生产者和消费者 Kafka生产者 消息发送的流程 发送方式 发送并忘记 同步发送 异步发送 生产者属性配置 序列化器 分区器 自定义分区器 Kafka消费者 消费者属性配置 消费者基础概 ...

  2. Kafka生产者与消费者详解

    什么是 Kafka Kafka 是由 Linkedin 公司开发的,它是一个分布式的,支持多分区.多副本,基于 Zookeeper 的分布式消息流平台,它同时也是一款开源的基于发布订阅模式的消息引擎系 ...

  3. Kafka 多话题消费者

    卡夫卡多主题消费者 支持的管道类型: 数据收集器 卡夫卡多主题消费者源从阿帕奇卡集群中的多个主题读取数据.源可以使用多个线程来启用数据的并行处理.如果愿意,您可以使用 Kafka 使用者通过单个线程从 ...

  4. Kafka学习之消费者

    Kafka学习之消费者 前言 本博客主要介绍up在学习kafka中间件时候觉得需要记录的知识点. 内容 1.消费者与消费组 消费者(Consumer)负责订阅Kafka中的主题(Topic),并且从订 ...

  5. pykafka连接重要使用pykafka,kafka-python的api开发kafka生产者和消费者

    https://pykafka.readthedocs.io/en/latest/api/producer.html 说明文档 </div><h2 class="heade ...

  6. 关于Kafka 的 consumer 消费者手动提交详解

    前言 在上一篇 Kafka使用Java实现数据的生产和消费demo 中介绍如何简单的使用kafka进行数据传输.本篇则重点介绍kafka中的 consumer 消费者的讲解. 应用场景 在上一篇kaf ...

  7. Kafka 生产者、消费者命令行操作

    Kafka 生产者.消费者命令行操作 1.查看操作生产者命令参数 bin/kafka-console-producer.sh 参数 --bootstrap-server <String: ser ...

  8. [kafka]kafka术语白话

    本文致力于写一篇非技术人员也能看懂的kafka术语介绍. kafka是一个消息引擎系统,它可以传递消息,也具有转换消息的能力,对于今天的主题来说,我们关注传递消息的能力就够了,因为我们一般接触到的术语 ...

  9. [Kafka] Kafka基本架构

    [Kafka] Kafka基本架构 [Kafka] Kafka基本架构 [Kafka] Kafka基本架构 生产者Producer :生产信息: 消费者Consumer :订阅主题.消费信息: 代理B ...

最新文章

  1. Java项目:在线考试系统(java+springboot+vue+jsp+mysql+maven)
  2. 暑期集训5:并查集 线段树 练习题A:  HDU - 1232 ​​​​​​​
  3. OpenCV——KNN分类算法 摘
  4. linux 交叉编译选项
  5. 收集服务器配置资源信息
  6. mac golang grpc proto pb文件生成go文件.md
  7. Xadmin添加用户小组件出错
  8. 灰色关联分析_灰色关联分析模型研究综述
  9. Shell-杀死指定进程
  10. unity visual effect Graph 1
  11. 升级计算机的图形卡和驱动程序,Win10更新显卡驱动程序后无法开机怎么办?解决方案...
  12. 万用表蜂鸣器档の响一声
  13. 视频教程-SpringBoot核心技术-Java
  14. centos7的LAMP多机LAP+MYSQL
  15. 会议室预约系统 会议预约 会议预约触摸屏 会议预约管理系统
  16. 解构「私域流量」(一)|底层思维
  17. 设置Gridview的列是否自动换行
  18. Xamarin.Forms——上传图片
  19. Python爬取4K图片
  20. 卡牌游戏——吃面包(人机对决 和 机机对决)

热门文章

  1. 腾讯公司被法院强制执行25元,刚好是QQ超级会员的价格
  2. 爱奇艺纪录片《棒!少年》《从长安到罗马》入选广电总局“2020年优秀国产纪录片集锦”...
  3. 谷歌将推出新版Pixel 4a 5G:搭载骁龙765G处理器 售价下降至3200元
  4. 华为EMUI 11开启公测 这十款机型率先尝鲜
  5. 苹果WWDC 2020回顾:来看看这个安卓味的iOS 14!
  6. 得物App联合Zippo推出限量款打火机 首批开售十分钟即售罄
  7. 799元首发!小米手表Color:14天超长续航、专业运动健康管理
  8. 对刚iPad!华为最强Pad发布,独揽四项全球第一,3299元起!
  9. 看呆了!日本男粉丝凭瞳孔倒影找到偶像住所 实施猥亵...
  10. “别了,小黄文” 微信打击低俗小说:2019年处理违规账号6.6万+