public class MicroBlogTopology {
public static void main(String[] args) throws Exception {
TopologyBuilder builder = new TopologyBuilder();
// 设置数据源组件
builder.setSpout("WeiboSpout", new MicroBlogSpout(), 1);
// 设置分词组件
builder.setBolt("TokenizerBolt", new WordSplitBolt(), 4).shuffleGrouping("WeiboSpout");
// 设置过滤组件
builder.setBolt("FilterBolt", new FilterBolt(), 4).shuffleGrouping("TokenizerBolt");
// 设置统计组件
builder.setBolt("StatisticianBolt", new WordCountBolt(), 4).fieldsGrouping("FilterBolt", new Fields("word"));
// 设置排序组件
builder.setBolt("SequencerBolt", new TopNWordsBolt(10), 1).globalGrouping("StatisticianBolt");
// 设置输出组件
builder.setBolt("OutputBolt", new PrintBolt(), 1).globalGrouping("SequencerBolt");
// 设置任务并行度
Config config = new Config();
config.setNumWorkers(4);
config.setMaxSpoutPending(5000);
// 提交Topology
StormSubmitter.submitTopology("MicroBlogTopology",config, builder.createTopology());
}
}
【无标题】
最新推荐文章于 2024-08-16 23:08:28 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)