zoukankan      html  css  js  c++  java
  • 3、SpringBoot集成Storm WorldCount

    RandomSentenceSpout

    //数据源,在已知的英文句子中,随机发送一条句子出去。
    public class RandomSentenceSpout extends BaseRichSpout {
    
        //用来收集Spout输出的tuple
        private SpoutOutputCollector collector;
        private Random random;
    
    
        //该方法调用一次,主要由storm框架传入SpoutOutputCollector
        @Override
        public void open(Map map, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector) {
            this.collector = collector;
            random = new Random();
            //连接kafka mysql ,打开本地文件
        }
    
        /**
         * 上帝之手
         * while(true)
         *      spout.nextTuple()
         */
        @Override
        public void nextTuple() {
            String[] sentences = new String[]{
                    "the cow jumped over the moon","the dog jumped over the moon",
                    "the pig jumped over the gun","the fish jumped over the moon","the duck jumped over the moon",
                    "the man jumped over the sun","the girl jumped over the sun","the boy jumped over the sun"
            };
            String sentence = sentences[random.nextInt(sentences.length)];
    
            collector.emit(new Values(sentence));
    
            System.out.println("RandomSentenceSpout 发送数据:"+sentence);
        }
    
        //消息源可以发射多条消息流stream
        @Override
        public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
            outputFieldsDeclarer.declare(new Fields("sentence"));
        }
    }
    
    
  • 相关阅读:
    第三周作业
    第二周作业 编程总结
    编程总结二 求最大值及其下标
    编程总结一 查找整数
    第十周课程总结
    第九周课程总结&实验报告(七
    第八周课程总结&实验报告(六)
    第七周课程总结&实验报告(五)
    第六周&java实验报告四
    第五周的作业
  • 原文地址:https://www.cnblogs.com/xidianzxm/p/10751382.html
Copyright © 2011-2022 走看看