转载 ---kafka集群消费之ConsumerRecord类

本文深入解析了Kafka中ConsumerRecord类的结构与功能,包括其继承关系、字段、构造函数及方法摘要,阐述了如何从特定主题和分区接收记录,并提供了关于校验和、时间戳、序列化大小等关键信息的获取方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



  • public final class ConsumerRecord <K,V> 
    extends Object
    从Kafka收到的键/值对。这包括主题名称和分区号,从中接收记录以及指向Kafka分区中记录的偏移量。
    • 构造函数摘要

      构造函数  
      构造函数和描述
      ConsumerRecord(String topic, int partition, long offset, K key, V value)
      创建从指定主题和分区接收的记录(在消息格式支持的时间戳之前和公开序列化元数据之前提供与Kafka 0.9的兼容性)。
      ConsumerRecord(String topic, int partition, long offset, long timestamp, org.apache.kafka.common.record.TimestampType timestampType, long checksum, int serializedKeySize, int serializedValueSize, K key, V value)
      创建从指定主题和分区接收的记录
    • 现场细节

      • NO_TIMESTAMP
        public static final long NO_TIMESTAMP
        也可以看看:
        常数字段值
      • NULL_SIZE
        public static final int NULL_SIZE
        也可以看看:
        常数字段值
      • NULL_CHECKSUM
        public static final int NULL_CHECKSUM
        也可以看看:
        常数字段值
    • 构造函数详细信息

      • ConsumerRecord
        public ConsumerRecord(String  topic,
                      int分区,
                      长偏移,
                      K  键,
                       V  值)
        创建从指定主题和分区接收的记录(在消息格式支持的时间戳之前和公开序列化元数据之前提供与Kafka 0.9的兼容性)。
        参数:
        topic - 收到此记录的主题
        partition - 收到此记录的主题分区
        offset - 此记录在相应Kafka分区中的偏移量
        key - 记录的密钥(如果存在)(允许为null)
        value - 记录内容
      • ConsumerRecord
        public ConsumerRecord(String  topic,
                      int分区,
                      长偏移,
                      很长的时间戳,
                      org.apache.kafka.common.record.TimestampType timestampType,
                      长校验和,
                      int serializedKeySize,
                      int serializedValueSize,
                      K  键,
                       V  值)
        创建从指定主题和分区接收的记录
        参数:
        topic - 收到此记录的主题
        partition - 收到此记录的主题分区
        offset - 此记录在相应Kafka分区中的偏移量
        timestamp - 记录的时间戳。
        timestampType - 时间戳类型
        checksum - 完整记录的校验和(CRC32)
        serializedKeySize - 序列化密钥的长度
        serializedValueSize - 序列化值的长度
        key - 记录的密钥(如果存在)(允许为null)
        value - 记录内容
    • 方法细节

      • 话题
        public  String  topic()
        收到此记录的主题
      • 划分
        public int partition()
        从中接收此记录的分区
      • 公钥  K  键()
        密钥(如果未指定密钥,则为null)
      • 公共  V  值()
        价值
      • 抵消
        公共长偏移量()
        此记录在相应Kafka分区中的位置。
      • 时间戳
        公共长时间戳()
        此记录的时间戳
      • timestampType
        public org.apache.kafka.common.record.TimestampType timestampType()
        此记录的时间戳类型
      • 校验
        公共长校验和()
        记录的校验和(CRC32)。
      • serializedKeySize
        public int serializedKeySize()
        序列化未压缩密钥的大小(以字节为单位)。如果key为null,则返回的大小为-1。
      • serializedValueSize
        public int serializedValueSize()
        序列化未压缩值的大小(以字节为单位)。如果value为null,则返回的大小为-1。
                                </div><div><div></div></div>
            <link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-60ecaf1f42.css" rel="stylesheet">
                                            <div class="more-toolbox">
            <div class="left-toolbox">
                <ul class="toolbox-list">
                    
                    <li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
                        <use xlink:href="#csdnc-thumbsup"></use>
                    </svg><span class="name">点赞</span>
                    <span class="count"></span>
                    </a></li>
                    <li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{&quot;mod&quot;:&quot;popu_824&quot;}"><svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-csdnc-Collection-G"></use>
                    </svg><span class="name">收藏</span></a></li>
                    <li class="tool-item tool-active is-share"><a href="javascript:;" data-report-click="{&quot;mod&quot;:&quot;1582594662_002&quot;}"><svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-csdnc-fenxiang"></use>
                    </svg>分享</a></li>
                    <!--打赏开始-->
                                            <!--打赏结束-->
                                            <li class="tool-item tool-more">
                        <a>
                        <svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
                        </a>
                        <ul class="more-box">
                            <li class="item"><a class="article-report">文章举报</a></li>
                        </ul>
                    </li>
                                        </ul>
            </div>
                        </div>
        <div class="person-messagebox">
            <div class="left-message"><a href="https://blog.csdn.net/qq_37191690">
                <img src="https://profile.csdnimg.cn/6/2/D/3_qq_37191690" class="avatar_pic" username="qq_37191690">
                                        <img src="https://g.csdnimg.cn/static/user-reg-year/1x/3.png" class="user-years">
                                </a></div>
            <div class="middle-message">
                                    <div class="title"><span class="tit"><a href="https://blog.csdn.net/qq_37191690" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}" target="_blank">一个小小bug</a></span>
                                        </div>
                <div class="text"><span>发布了3 篇原创文章</span> · <span>获赞 6</span> · <span>访问量 1万+</span></div>
            </div>
                            <div class="right-message">
                                        <a href="https://im.csdn.net/im/main.html?userName=qq_37191690" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
                    </a>
                                                        <a class="btn btn-sm  bt-button personal-watch" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}">关注</a>
                                </div>
                        </div>
                </div>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值