当前位置: 首页 > news >正文

河北省建设注册中心网站html5网络公司网站模板

河北省建设注册中心网站,html5网络公司网站模板,大良网站建设市场,网站开发技术视频ConsumerRecord 是 Apache Kafka 消费者从主题中读取消息时的核心数据结构,每条消息都会被封装为一个 ConsumerRecord 对象。它包含了消息的元数据(如来源、位置)和实际内容,是消费者处理消息的基础单元。以下是其核心要点&#x…

ConsumerRecord 是 Apache Kafka 消费者从主题中读取消息时的核心数据结构,每条消息都会被封装为一个 ConsumerRecord 对象。它包含了消息的元数据(如来源、位置)和实际内容,是消费者处理消息的基础单元。以下是其核心要点:

ConsumerRecord 的结构与字段

每个 ConsumerRecord 包含以下关键信息:

topic:消息所属的 Kafka 主题名称(字符串)

partition:消息所在分区的编号(整数)

offset:消息在分区中的唯一位置标识(长整数),用于追踪消费进度

key:消息的键(泛型),通常用于分区路由或业务标识(如订单ID

value:消息的值(泛型),即实际传输的数据(如 JSON 字符串、二进制数据等)

timestamp:消息的时间戳(长整数),表示消息生成或追加到分区的时间

headers:消息头(键值对集合),用于传递业务元数据(如消息类型、版本号)

checksum:校验和(长整数,已逐步弃用),用于验证消息完整性

在代码中的使用示例

在 Java 或 Spring Kafka 中,ConsumerRecord 通常通过消费者监听器(如 @KafkaListener)接收并处理:

@KafkaListener(topics = "orders")
public void handleOrder(ConsumerRecord<String, Order> record) {String key = record.key();         // 获取消息键(如订单ID)Order value = record.value();     // 获取消息值(如订单对象)String topic = record.topic();     // 获取主题名称long offset = record.offset();     // 获取消息偏移量// 处理业务逻辑...
}

源码

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//package org.apache.kafka.clients.consumer;import java.util.Optional;
import org.apache.kafka.common.header.Headers;
import org.apache.kafka.common.header.internals.RecordHeaders;
import org.apache.kafka.common.record.DefaultRecord;
import org.apache.kafka.common.record.TimestampType;public class ConsumerRecord<K, V> {public static final long NO_TIMESTAMP = -1L;public static final int NULL_SIZE = -1;public static final int NULL_CHECKSUM = -1;private final String topic;private final int partition;private final long offset;private final long timestamp;private final TimestampType timestampType;private final int serializedKeySize;private final int serializedValueSize;private final Headers headers;private final K key;private final V value;private final Optional<Integer> leaderEpoch;private volatile Long checksum;public ConsumerRecord(String topic, int partition, long offset, K key, V value) {this(topic, partition, offset, -1L, TimestampType.NO_TIMESTAMP_TYPE, -1L, -1, -1, key, value);}public ConsumerRecord(String topic, int partition, long offset, long timestamp, TimestampType timestampType, long checksum, int serializedKeySize, int serializedValueSize, K key, V value) {this(topic, partition, offset, timestamp, timestampType, checksum, serializedKeySize, serializedValueSize, key, value, new RecordHeaders());}public ConsumerRecord(String topic, int partition, long offset, long timestamp, TimestampType timestampType, Long checksum, int serializedKeySize, int serializedValueSize, K key, V value, Headers headers) {this(topic, partition, offset, timestamp, timestampType, checksum, serializedKeySize, serializedValueSize, key, value, headers, Optional.empty());}public ConsumerRecord(String topic, int partition, long offset, long timestamp, TimestampType timestampType, Long checksum, int serializedKeySize, int serializedValueSize, K key, V value, Headers headers, Optional<Integer> leaderEpoch) {if (topic == null) {throw new IllegalArgumentException("Topic cannot be null");} else if (headers == null) {throw new IllegalArgumentException("Headers cannot be null");} else {this.topic = topic;this.partition = partition;this.offset = offset;this.timestamp = timestamp;this.timestampType = timestampType;this.checksum = checksum;this.serializedKeySize = serializedKeySize;this.serializedValueSize = serializedValueSize;this.key = key;this.value = value;this.headers = headers;this.leaderEpoch = leaderEpoch;}}public String topic() {return this.topic;}public int partition() {return this.partition;}public Headers headers() {return this.headers;}public K key() {return this.key;}public V value() {return this.value;}public long offset() {return this.offset;}public long timestamp() {return this.timestamp;}public TimestampType timestampType() {return this.timestampType;}/** @deprecated */@Deprecatedpublic long checksum() {if (this.checksum == null) {this.checksum = DefaultRecord.computePartialChecksum(this.timestamp, this.serializedKeySize, this.serializedValueSize);}return this.checksum;}public int serializedKeySize() {return this.serializedKeySize;}public int serializedValueSize() {return this.serializedValueSize;}public Optional<Integer> leaderEpoch() {return this.leaderEpoch;}public String toString() {return "ConsumerRecord(topic = " + this.topic + ", partition = " + this.partition + ", leaderEpoch = " + this.leaderEpoch.orElse((Object)null) + ", offset = " + this.offset + ", " + this.timestampType + " = " + this.timestamp + ", serialized key size = " + this.serializedKeySize + ", serialized value size = " + this.serializedValueSize + ", headers = " + this.headers + ", key = " + this.key + ", value = " + this.value + ")";}
}
http://www.dtcms.com/a/496519.html

相关文章:

  • 4.类和对象(上)
  • 高端手机“探花”之争,AI会成为“胜负手”吗?
  • 福建省住房和城乡建设厅官方网站做网站挂广告赚多少
  • 门户网站直接登录系统wordpress吐槽源码
  • 网站中的flash龙岩做网站怎么做
  • Cucumber + Playwright framework based on javascript
  • 关于电子商务网站建设的论文广告传媒公司介绍
  • 武威建设厅网站建设企业网站进去无法显示
  • 一台网站服务器多少钱网站建设业务员培训
  • 网站建设如何赚钱wordpress主题设置选择
  • SVN 非页面操作 锁定单个cell
  • 布恩网站删除西峡微网站开发
  • 网站后台图片模板wordpress 手机发文
  • 网站建设与用户需求分析国家企业信用信息公示系统查询
  • 李飞飞 world labs最新文章 RTFM: A Real-Time Frame Model 翻译及思考
  • Prism框架核心对象补充:区域上下文与模块化设计
  • 广州那里有学做拼多多网站的天津网站建设市场
  • 福建闽东建设网站设计logo网站 生成器
  • Git合并分支:从命令行到图形化工具
  • 低价建网站wordpress添加友链申请
  • 长沙手机app网站开发哈尔滨网站制作哪里专业
  • 从Backtrader到Freqtrade:搭建自己的全自动量化平台
  • C标准库--类型限制<limits.h>
  • 网页设计新建站点wordpress 数据库设置
  • 外贸机械网站建设域名查询168
  • FFmpeg 基本API avio_write函数内部调用流程分析
  • 怎么优化一个网站关键词wordpress 摄影工作室主题
  • 2025Java高质量面试真题汇总!
  • Edge Wallet数字货币钱包安全可靠吗?浅聊数字钱包
  • 宁波网站建设是哪家便宜如何建个使用自己帐户的网站