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

storm Tuple详解

Storm Tuple 是 Apache Storm 拓扑中数据流动的‌最小不可分单元‌,本质为‌带名称的有序值列表‌,承载组件间传递的所有实时数据 。‌‌

核心定义与结构

  • 本质‌:命名的值列表(Named List of Values),字段无需显式声明类型,动态解析;逻辑上类似数据库一行记录或 Key-Value 映射,但底层按‌索引顺序‌存储值列表 。
  • 组成‌:由‌字段名(Fields)‌和‌字段值(Values)‌构成,支持基本类型(int, long, double, boolean, string 等)、字节数组及实现Serializable接口的自定义对象 。
  • 定位‌:Stream(流)由无限 Tuple 序列组成,Tuple 是 Spout 产生、Bolt 处理与转发的唯一数据载体 。‌‌

数据类型与序列化

  • 默认支持‌:integer, float, double, long, short, string, byte, boolean, byte[] (binary)。
  • 自定义类型‌:需实现 JavaSerializable接口,Storm 通过序列化机制在网络间传输 。
  • 取值方式‌:支持通过‌索引‌(getInteger(0))或‌字段名‌(getStringByField("log"))获取值,后者更可读且不易出错 。‌‌

生命周期与可靠性机制

  1. 生成‌:Spout 的nextTuple()通过OutputCollector.emit()发射 Tuple,并关联唯一的MessageId
  2. 追踪‌:Storm 内部 Acker 组件构建“元组树”,追踪该 Tuple 及其衍生 Tuple 的处理状态。
  3. 确认‌:Bolt 处理完必须调用collector.ack(input)IBasicBolt可自动完成);超时或调用fail()则触发 Spout 重发 。
  4. 终结‌:成功则ack,失败或超时则fail,由源头 Spout 决定重试或丢弃 。‌‌

关键 API 操作示例

// 1. 定义输出字段 (在 Bolt/Spout 的 declareOutputFields 中) declarer.declare(new Fields("field_name_1", "field_name_2")); // 2. 发射 Tuple (在 Bolt/Spout 中) collector.emit(new Values(val1, val2)); // 3. 读取输入 Tuple (在 Bolt execute 方法中) int id = input.getIntegerByField("id"); // 按名取值 String data = input.getString(0); // 按索引取值 Values output = new Values(id * 2, data); // 构造新值 collector.emit(input, output); // 锚定原 Tuple 以确认可靠性 collector.ack(input); // 确认处理成功 ```‌‌:ml-citation{ref="1,8" appearance="aggregated" data="citationList"} ### 注意事项 - ‌**线程安全**‌:`OutputCollector` 非线程安全,emit/ack/fail 必须在同一线程执行 。 - ‌**性能**‌:频繁创建大对象或复杂自定义类型会增加序列化开销;优先使用基本类型。 - ‌**Trident 扩展**‌:Trident 抽象层使用 `TridentTuple`,提供批处理语义,接口与原生 Tuple 类似但处于不同包路径 。‌‌:ml-citation{ref="9,7" appearance="aggregated" data="citationList"} :::ml-data{name=citationList} ```json [{"source":{"logo":"https://search-operate.cdn.bcebos.com/175c73f4973c6168ed6acae5b638fa15.png","name":"博客园"},"isVideo":false,"title":"Storm概念学习系列之Tuple元组(数据载体) - 大数据和AI躺过的坑 - 博客园","thumbnail":"http://t7.baidu.com/it/u=4129332916,2995855404&fm=217&app=126&f=JPEG?w=800&h=423&s=45F43C7211C2694B5C61D8CB030010B2","linkInfo":{"data-click-info":"{}","href":"https://www.cnblogs.com/zlslch/p/5989281.html","target":"_blank","data-noblank":true,"data-show":"list","data-show-ext":"{\"pos\":\"1\",\"component_content\":{\"component_name\":\"reference\"}}"}},{"source":{"logo":"","name":"看云"},"isVideo":false,"title":"2.Storm 核心概念详解","thumbnail":"http://t7.baidu.com/it/u=3576538536,1727813310&fm=217&app=126&f=JPEG?w=757&h=317&s=8CEEFC12A70C7D431C7C085903005072","linkInfo":{"data-click-info":"{}","href":"https://www.kancloud.cn/imnotdown1019/java_core_full/2157757","target":"_blank","data-noblank":true,"data-show":"list","data-show-ext":"{\"pos\":\"2\",\"component_content\":{\"component_name\":\"reference\"}}"}},{"source":{"logo":"https://search-operate.cdn.bcebos.com/175c73f4973c6168ed6acae5b638fa15.png","name":"博客园"},"isVideo":false,"title":"storm并发度理解","thumbnail":"http://t8.baidu.com/it/u=478955224,3561615887&fm=217&app=126&f=JPEG?w=563&h=341&s=1A9EEC021DDF41CA4A692CDA030040B3","linkInfo":{"data-click-info":"{}","href":"https://www.cnblogs.com/sunfie/p/7274145.html","target":"_blank","data-noblank":true,"data-show":"list","data-show-ext":"{\"pos\":\"3\",\"component_content\":{\"component_name\":\"reference\"}}"}},{"source":{"logo":"https://search-operate.cdn.bcebos.com/175c73f4973c6168ed6acae5b638fa15.png","name":"博客园"},"isVideo":false,"title":"Storm 核心组件详解及storm编程核心Api","thumbnail":"http://t8.baidu.com/it/u=1871709672,1595958830&fm=217&app=126&f=JPEG?w=799&h=454&s=00727532035240650CD4D4DE0300C0B3","linkInfo":{"data-click-info":"{}","href":"https://www.cnblogs.com/Transkai/p/10891242.html","target":"_blank","data-noblank":true,"data-show":"list","data-show-ext":"{\"pos\":\"4\",\"component_content\":{\"component_name\":\"reference\"}}"}},{"source":{"logo":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3385518650,4195902768&fm=195&app=88&f=JPEG?w=200&h=200","name":"51CTO博客"},"isVideo":false,"title":"2、Storm中的一些概念理解","thumbnail":"","linkInfo":{"data-click-info":"{}","href":"https://blog.51cto.com/u_15300875/3090664","target":"_blank","data-noblank":true,"data-show":"list","data-show-ext":"{\"pos\":\"5\",\"component_content\":{\"component_name\":\"reference\"}}"}},{"source":{"logo":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3385518650,4195902768&fm=195&app=88&f=JPEG?w=200&h=200","name":"51CTO博客"},"isVideo":false,"title":"storm tuple 结构 storm的原理","thumbnail":"http://t8.baidu.com/it/u=626157831,954645765&fm=217&app=137&f=JPEG?w=753&h=411&s=08887C321B02404B0E4D2CDA030080B2","linkInfo":{"data-click-info":"{}","href":"https://blog.51cto.com/u_16099190/6724295","target":"_blank","data-noblank":true,"data-show":"list","data-show-ext":"{\"pos\":\"6\",\"component_content\":{\"component_name\":\"reference\"}}"}},{"source":{"logo":"","name":"storm.apache.org"},"isVideo":false,"title":"TridentTuple (Storm 2.6.0 API)","thumbnail":"","linkInfo":{"data-click-info":"{}","href":"https://storm.apache.org/releases/2.6.0/javadocs/org/apache/storm/trident/tuple/TridentTuple.html","target":"_blank","data-noblank":true,"data-show":"list","data-show-ext":"{\"pos\":\"7\",\"component_content\":{\"component_name\":\"reference\"}}"}},{"source":{"logo":"https://search-operate.cdn.bcebos.com/175c73f4973c6168ed6acae5b638fa15.png","name":"博客园"},"isVideo":false,"title":"Storm—Storm常用API - 花未全开*月未圆 - 博客园","thumbnail":"http://t9.baidu.com/it/u=3831325093,3352837103&fm=217&app=126&f=JPEG?w=799&h=381&s=14A67C321109414958D194DA030060B1","linkInfo":{"data-click-info":"{}","href":"https://www.cnblogs.com/tesla-turing/p/13699003.html","target":"_blank","data-noblank":true,"data-show":"list","data-show-ext":"{\"pos\":\"8\",\"component_content\":{\"component_name\":\"reference\"}}"}},{"source":{"logo":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3385518650,4195902768&fm=195&app=88&f=JPEG?w=200&h=200","name":"51CTO博客"},"isVideo":false,"title":"Storm常用API storm approaching","thumbnail":"","linkInfo":{"data-click-info":"{}","href":"https://blog.51cto.com/u_16213609/7812923","target":"_blank","data-noblank":true,"data-show":"list","data-show-ext":"{\"pos\":\"9\",\"component_content\":{\"component_name\":\"reference\"}}"}},{"source":{"logo":"","name":"storm.apache.org"},"isVideo":false,"title":"TupleValueMapper (Storm 2.6.0 API)","thumbnail":"","linkInfo":{"data-click-info":"{}","href":"https://storm.apache.org/releases/2.6.0/javadocs/org/apache/storm/streams/operations/mappers/TupleValueMapper.html","target":"_blank","data-noblank":true,"data-show":"list","data-show-ext":"{\"pos\":\"10\",\"component_content\":{\"component_name\":\"reference\"}}"}},{"source":{"logo":"https://search-operate.cdn.bcebos.com/175c73f4973c6168ed6acae5b638fa15.png","name":"博客园"},"isVideo":false,"title":"Storm storm API(二) - houstao - 博客园","thumbnail":"http://t7.baidu.com/it/u=1723174321,3892021495&fm=217&app=126&f=JPEG?w=800&h=504&s=7AB2C04C9AAF936C06D1E4070300E0C3","linkInfo":{"data-click-info":"{}","href":"https://www.cnblogs.com/houstao/p/11473880.html","target":"_blank","data-noblank":true,"data-show":"list","data-show-ext":"{\"pos\":\"11\",\"component_content\":{\"component_name\":\"reference\"}}"}},{"source":{"logo":"","name":"storm.apache.org"},"isVideo":false,"title":"TupleValueMappers (Storm 2.6.2 API)","thumbnail":"","linkInfo":{"data-click-info":"{}","href":"https://storm.apache.org/releases/2.6.2/javadocs/org/apache/storm/streams/operations/mappers/TupleValueMappers.html","target":"_blank","data-noblank":true,"data-show":"list","data-show-ext":"{\"pos\":\"12\",\"component_content\":{\"component_name\":\"reference\"}}"}},{"source":{"logo":"https://search-operate.cdn.bcebos.com/175c73f4973c6168ed6acae5b638fa15.png","name":"博客园"},"isVideo":false,"title":"Storm的数据处理编程单元:Bolt 学习整理","thumbnail":"","linkInfo":{"data-click-info":"{}","href":"https://www.cnblogs.com/yangsy0915/p/5136331.html","target":"_blank","data-noblank":true,"data-show":"list","data-show-ext":"{\"pos\":\"13\",\"component_content\":{\"component_name\":\"reference\"}}"}},{"source":{"logo":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3385518650,4195902768&fm=195&app=88&f=JPEG?w=200&h=200","name":"51CTO博客"},"isVideo":false,"title":"storm ui参数","thumbnail":"http://t7.baidu.com/it/u=816220488,671848165&fm=217&app=137&f=JPEG?w=800&h=398&s=D196EE3A935B41C84E4930D2030090B2","linkInfo":{"data-click-info":"{}","href":"https://blog.51cto.com/u_14731/14224758","target":"_blank","data-noblank":true,"data-show":"list","data-show-ext":"{\"pos\":\"14\",\"component_content\":{\"component_name\":\"reference\"}}"}},{"source":{"logo":"","name":"storm.apache.org"},"isVideo":false,"title":"Storm Metrics","thumbnail":"","linkInfo":{"data-click-info":"{}","href":"https://storm.apache.org/releases/2.6.1/Metrics.html","target":"_blank","data-noblank":true,"data-show":"list","data-show-ext":"{\"pos\":\"15\",\"component_content\":{\"component_name\":\"reference\"}}"}},{"source":{"logo":"https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3385518650,4195902768&fm=195&app=88&f=JPEG?w=200&h=200","name":"51CTO博客"},"isVideo":false,"title":"storm教程 stormst","thumbnail":"http://t8.baidu.com/it/u=1635551756,1339453275&fm=217&app=126&f=JPEG?w=495&h=351&s=B9A87C332952D9CE0EFC94CE0300A0B3","linkInfo":{"data-click-info":"{}","href":"https://blog.51cto.com/u_16213641/7011334","target":"_blank","data-noblank":true,"data-show":"list","data-show-ext":"{\"pos\":\"16\",\"component_content\":{\"component_name\":\"reference\"}}"}},{"source":{"logo":"https://search-operate.cdn.bcebos.com/175c73f4973c6168ed6acae5b638fa15.png","name":"博客园"},"isVideo":false,"title":"Storm概念学习系列之Tuple元组(数据载体) - 大数据和AI躺过的坑 - 博客园","thumbnail":"http://t7.baidu.com/it/u=4129332916,2995855404&fm=217&app=126&f=JPEG?w=800&h=423&s=45F43C7211C2694B5C61D8CB030010B2","linkInfo":{"data-click-info":"{}","href":"https://www.cnblogs.com/zlslch/p/5989281.html","target":"_blank","data-noblank":true,"data-show":"list","data-show-ext":"{\"pos\":\"17\",\"component_content\":{\"component_name\":\"reference\"}}"}},{"source":{"logo":"https://search-operate.cdn.bcebos.com/175c73f4973c6168ed6acae5b638fa15.png","name":"博客园"},"isVideo":false,"title":"Storm Trident API - 木易森林 - 博客园","thumbnail":"","linkInfo":{"data-click-info":"{}","href":"https://www.cnblogs.com/senlinyang/p/8081447.html","target":"_blank","data-noblank":true,"data-show":"list","data-show-ext":"{\"pos\":\"18\",\"component_content\":{\"component_name\":\"reference\"}}"}}]
http://www.jsqmd.com/news/1217849/

相关文章:

  • Lightning AI GPU Marketplace:跨云AI算力的统一抽象层
  • ShaderGraph沃罗诺伊噪声:从原理到实战,打造程序化纹理与材质
  • 如何撰写高质量的计算机课程设计报告
  • 万国中国官方售后服务中心|地址与联系电话权威信息通告(2026年7月最新) - 万国中国官方服务中心
  • Go单元测试中内联优化导致的打桩失效问题解析
  • tox + testr 单元测试工作流程详解:从环境隔离到并行执行
  • 用 AI 做视频拉片:镜头切分与结构化分镜数据的自动化实践
  • 深入解析TI IVA2.2 EDMA TPTC寄存器:从原理到实战配置
  • 求大佬帮忙
  • 深入解析MMC/SD/SDIO主机控制器驱动开发:从寄存器配置到实战调试
  • Cursor、Codex、Claude 代码评审、循环迭代编码(Loop Coding)完整开发流程拆解
  • 宝珀中国官方专柜客户服务热线权威信息声明(2026年7月最新) - 宝珀官方售后服务中心
  • Unity Meta Quest开发:Tracking Origin Type原理与实战配置指南
  • Nginx主动防御配置实战:构建Cloudflare后的第二道安全防线
  • 3个简单步骤彻底告别键盘连击烦恼:让老旧机械键盘重获新生
  • 安卓网络请求框架android-async-http详解与优化实践
  • 智慧食堂系统源码开发指南:采购、库存、配送、结算一体化平台如何实现?
  • 嵌入式系统看门狗定时器原理与TI OMAP实战配置详解
  • 嵌入式Linux与AI Agent开发:技术对比、薪资分析与学习路径
  • 开发必备:常用模块分类解析与最佳实践
  • Meshroom 3D重建免费软件:从零开始创建专业级三维模型的完整指南
  • 每天只有半小时复盘,量化软件先比较提醒准确率和处理成本
  • Kaggle竞赛四维解构法:指标、数据结构、时间逻辑与算力约束
  • 快速理解js原型链
  • HX4004A-MFC开关电容升压芯片:锂电池至5V转换实战指南
  • 程序员不会消失,但“只会写代码”的程序员会消失
  • 2026年最新教程:几张图片怎么竖着拼在一起 亲测免安装的实用方法 - 玩机日常
  • Unity游戏无声问题排查:从AudioSource到AudioListener的完整解决方案
  • IPXWrapper:让经典游戏在现代Windows上重获网络对战能力的终极指南
  • Android地图定位功能实现与优化指南