storm中declareOutputFields方法的使用规则及与fieldsGrouping方法的联系
declareOutputFields方法中声明了该bolt/spout输出的字段个数,供下游使用,在该bolt中的execute方法中,emit发射的字段个数必须和声明的相同,否则报错:Tuple created with wrong number of fields. Expected 2 fields but got 1 fields。
fieldsGrouping方法设定从上一个bolt中获取哪些fields。fieldsGrouping("2", new Fields("ahah","bb")),Fields中的参数名字必须和上一个bolt中声明的字段名字相同,否则报错:“Topology submission exception. (topology name='HelloStorm') #<InvalidTopologyException InvalidTopologyException(msg:Component: [3] subscribes from stream: [default] of component [2] with non-existent fields: #{"ahah1"})>
本文详细介绍了Apache Storm中declareOutputFields方法的使用规则及其与fieldsGrouping方法的关系。前者用于声明bolt/spout输出字段数量,后者则定义了从上游bolt接收特定字段的方式。
731

被折叠的 条评论
为什么被折叠?



