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"));
        }
    }
    
    
  • 相关阅读:
    MyBatis java and MySql local variables
    FileReader 基本介绍
    MyBatis插入多条
    mysql批量更新
    转载:mybatis自动生成
    Redis Replication
    Redis 持久化
    Python 调用 Redis API
    Redis 数据类型
    Redis 单节点安装
  • 原文地址:https://www.cnblogs.com/xidianzxm/p/10751382.html
Copyright © 2011-2022 走看看