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"));
        }
    }
    
    
  • 相关阅读:
    中国剩余定理及其扩展
    扩展欧几里得
    乘法逆元
    58-63用ssh远程连接linux系统
    148复习前一天的内容
    165-168函数
    Linux运维命令总结(-)
    177流程控制经典案例讲解
    170-176流程控制
    161【案例讲解】存储过程
  • 原文地址:https://www.cnblogs.com/xidianzxm/p/10751382.html
Copyright © 2011-2022 走看看