mikechenjs 发表于 2019-8-21 16:24:49

import java.util.Map;
import org.apache.storm.spout.SpoutOutputCollector;
import org.apache.storm.task.TopologyContext;
import org.apache.storm.topology.OutputFieldsDeclarer;
import org.apache.storm.topology.base.BaseRichSpout;
import org.apache.storm.tuple.Fields;
import org.apache.storm.tuple.Values;
import org.apache.storm.utils.Utils;

/**
* 数据源
* @author zhengcy
*
*/
@SuppressWarnings("serial")
public class SentenceSpout extendsBaseRichSpout {
       
        private SpoutOutputCollector collector;
        private String[] sentences = {
                        "Apache Storm is a free and open source distributed realtime computation system",
                        "Storm makes it easy to reliably process unbounded streams of data",
                        "doing for realtime processing what Hadoop did for batch processing",
                        "Storm is simple", "can be used with any programming language",
                        "and is a lot of fun to use" };
        private int index = 0;

        @Override
        public void declareOutputFields(OutputFieldsDeclarer declarer) {
                //定义输出字段描述
                declarer.declare(new Fields("sentence"));
        }

        @SuppressWarnings("rawtypes")
        public void open(Map config, TopologyContext context,SpoutOutputCollector collector) {
                this.collector = collector;
        }

       
        public void nextTuple() {
               if(index >= sentences.length){
                        return;       
             }
               //发送字符串
                this.collector.emit(new Values(sentences));
                index++;
                Utils.sleep(1);
        }
}

————————————————
版权声明:本文为CSDN博主「zhengcongyi」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/congcong68/article/details/73013142

创造晴_Izlmm 发表于 2019-8-29 10:35:49

111111111111111111

81530280 发表于 2019-8-30 10:46:08

学习学习

zhqh2014 发表于 2019-8-30 12:07:59

谢谢分享

legnaoqun008 发表于 2019-9-2 22:53:55

DDDDDDDDDD

blues 发表于 2019-9-16 20:42:06

不错!

mao1723 发表于 2019-10-20 20:05:29

感谢分享

aaron3323 发表于 2019-10-30 16:43:17

RE: 华为云 CKA《kubernetes管理员实训》

liubingxin 发表于 2019-11-9 00:13:34

牛逼啊

randy1981 发表于 2019-11-9 08:48:40

谢谢分享!!

ok_wolf 发表于 2019-11-11 20:08:32

正需要,看看是不是想要的。谢谢楼主。

htbenetcom 发表于 2019-11-12 09:19:58

11111111111111111111

liubulong 发表于 2019-12-11 20:26:11

6666

aaaadd 发表于 2019-12-11 20:34:58

楼主给力

aaaadd 发表于 2019-12-11 20:35:48

楼主,给力

aaaadd 发表于 2019-12-11 20:36:45

11111

warren1119 发表于 2019-12-16 17:40:27

能下载不

liuhaijun 发表于 2019-12-17 15:39:22

新手学习,

sysy555 发表于 2019-12-22 23:13:37

谢谢 群主的分享

zengym 发表于 2020-1-7 10:03:41

华为云 CKA《kubernetes管理员实训》
页: 1 2 [3] 4
查看完整版本: 华为云 CKA《kubernetes管理员实训》