栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用Apache Storm Tuple

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用Apache Storm Tuple

使用所有字段作为值创建元组的另一种方法是只创建一个bean并将其传递给元组。

给定以下类别:

public class DataBean implements Serializable {    private static final long serialVersionUID = 1L;    // add more properties as necessary    int id;    String word;    public DataBean(int id, String word) {        setId(id);        setWord(word);    }    public int getId() {        return id;    }    public void setId(int id) {        this.id = id;    }    public String getWord() {        return word;    }    public void setWord(String word) {        this.word = word;    }}

一键创建并发出DataBean:

collector.emit(new Values(bean));

在目标螺栓中获取DataBean:

@Overridepublic void execute(Tuple tuple, BasicOutputCollector collector) {    try {        DataBean bean = (DataBean)tuple.getValue(0);        // do your bolt processing with the bean    } catch (Exception e) {        LOG.error("WordCountBolt error", e);        collector.reportError(e);    }       }

设置拓扑时,请不要忘记使bean可序列化并注册:

Config stormConfig = new Config();stormConfig.registerSerialization(DataBean.class);// more stuffStormSubmitter.submitTopology("MyTopologyName", stormConfig, builder.createTopology());

免责声明:Beans可以很好地用于随机分组。如果需要执行

fieldsGrouping
,则仍应使用原语。例如,在“字数统计”方案中,您需要按单词分组,以便发出:

collector.emit(new Values(word, bean));


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/497863.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号