我先试试这个Open Live Writer能不能用。
再在ScribeFire中修改一下已经发布的文章试试看。
这两个写博客的地方都没有原始的编辑器方便,可以插入代码,选择文章的分类。所以以后还有这个编辑器吧。
昨天搞定第一个简单的topology,今天看一个稍微复杂一点的topology,基本上和昨天的一样,这个代码是我在学习极客学院的storm实战的时候,自己照着写下来的。
这个Topology有一个spout输入,三个bolt处理,加上一个topology的类,一共是五个类。【还需要一个工具类】
第一:spout的代码---RandomSentenceSpout.java
随机的发出一条消息
1 package cn.aeths.storm.helloworld.spout; 2 3 import java.util.Map; 4 import java.util.Random; 5 6 import backtype.storm.spout.SpoutOutputCollector; 7 import backtype.storm.task.TopologyContext; 8 import backtype.storm.topology.OutputFieldsDeclarer; 9 import backtype.storm.topology.base.BaseRichSpout; 10 import backtype.storm.tuple.Fields; 11 import backtype.storm.tuple.Values; 12 import backtype.storm.utils.Utils; 13 14 //随机发送一条内置消息,继承BaseRichSpout/IRichSpout类 15 @SuppressWarnings("serial") 16 public class RandomSentenceSpout extends BaseRichSpout{ 17 18 SpoutOutputCollector spoutOutputCollector; 19 Random random; 20 21 //进行tuple处理的重要的方法 22 public void nextTuple() { 23 Utils.sleep(2000); 24 String[] sentences = new String[]{ 25 "Hello world", 26 "Big world", 27 "the cow jumped over the moon", "an apple a day keeps the doctor away", 28 "four score and seven years ago", "snow white and the seven dwarfs", 29 "i am at two with nature", 30 31 }; 32 //从sentences中随机获取一条语句,作为spout发送的消息 33 String sentence = sentences[random.nextInt(sentences.length)]; 34 //使用emit方法进行tuple发布,参数用Values声明 35 spoutOutputCollector.emit(new Values(sentence.trim().toLowerCase())); 36 } 37 38 //初始化工作,参数传递 39 public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) { 40 spoutOutputCollector = collector; 41 random = new Random(); 42 } 43 44 //消息保证机制中的ack确认方法 45 public void ack(Object id){ 46 47 } 48 //消息保证机制中的fail确认方法 49 public void fail(Object id){ 50 51 } 52 //声明字段 53 public void declareOutputFields(OutputFieldsDeclarer declarer) { 54 declarer.declare(new Fields("word")); 55 } 56 57 }
第二:bolt1的代码---WordNormalizerBolt.java
消息标准化
1 package cn.aeths.storm.helloworld.bolt; 2 3 import java.util.Map; 4 5 import backtype.storm.task.OutputCollector; 6 import backtype.storm.task.TopologyContext; 7 import backtype.storm.topology.IRichBolt; 8 import backtype.storm.topology.OutputFieldsDeclarer; 9 import backtype.storm.tuple.Fields; 10 import backtype.storm.tuple.Tuple; 11 import backtype.storm.tuple.Values; 12 13 //消息标准化 14 @SuppressWarnings("serial") 15 public class WordNormalizerBolt implements IRichBolt{ 16 17 //发射消息 18 private OutputCollector outputCollector; 19 20 //初始化方法 21 public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { 22 outputCollector = collector; 23 } 24 25 //执行订阅的tuple逻辑过程的方法 26 public void execute(Tuple input) { 27 String sentence = input.getString(0); 28 //获得每个输入的流,拆分成单个的字符串数组,对每个元素,发射出去 29 String[] words = sentence.split(" "); 30 for (String word : words) { 31 outputCollector.emit(new Values(word)); 32 } 33 } 34 public void cleanup() { 35 36 } 37 38 //字段声明 39 public void declareOutputFields(OutputFieldsDeclarer declarer) { 40 declarer.declare(new Fields("word")); 41 } 42 43 public Map<String, Object> getComponentConfiguration() { 44 return null; 45 } 46 47 }
第三:bolt2的代码---WordCountBolt.java
单词统计,实时获取词频前n的单词发射出去
1 package cn.aeths.storm.helloworld.bolt; 2 3 import java.util.HashMap; 4 import java.util.Map; 5 6 import backtype.storm.task.OutputCollector; 7 import backtype.storm.task.TopologyContext; 8 import backtype.storm.topology.IRichBolt; 9 import backtype.storm.topology.OutputFieldsDeclarer; 10 import backtype.storm.tuple.Fields; 11 import backtype.storm.tuple.Tuple; 12 import backtype.storm.tuple.Values; 13 import cn.aeths.storm.helloworld.util.MapSort; 14 15 //单词统计,实时获取词频前N的发射出去 16 @SuppressWarnings("serial") 17 public class WordCountBolt implements IRichBolt{ 18 19 Map< String, Integer> counters;//单词和词频的对应关系 20 private OutputCollector outputCollector; 21 22 23 @SuppressWarnings("rawtypes") 24 public void prepare(Map arg0, TopologyContext context, OutputCollector collector) { 25 outputCollector = collector; 26 counters = new HashMap<String, Integer>();//初始化 27 } 28 public void cleanup() { 29 30 } 31 32 public void execute(Tuple input) { 33 String str = input.getString(0); 34 if(!counters.containsKey(str)){ 35 counters.put(str, 1);//没有的话,给1 36 }else{ 37 Integer c = counters.get(str) +1; 38 counters.put(str, c);//有的话在原来的基础上加1 39 } 40 int num=8; 41 int length=0; 42 43 counters = MapSort.sortByValue(counters);//调用自己写的排序方法重新排序 44 45 if(num<counters.keySet().size()){ 46 length = num;//key的长度大于8的时候给length赋值就是8 47 }else{ 48 length = counters.keySet().size();//否则的话是多长就多长 49 } 50 51 String word = null; 52 53 int count=0; 54 for(String key:counters.keySet()){ 55 //对每一个输出的map都封装一下value为word 56 if(count>=length){//长度为0的就算了 57 break; 58 } 59 if(count==0){ 60 word="[" + key + "." + counters.get(key) + "]"; 61 }else{ 62 word=word+",[" +key +":"+counters.get(key) + "]"; 63 } 64 count++; 65 } 66 word ="The first" + num+ ": "+ word; 67 //发射出去 68 outputCollector.emit(new Values(word)); 69 } 70 71 72 73 public void declareOutputFields(OutputFieldsDeclarer declarer) { 74 declarer.declare(new Fields("word")); 75 } 76 77 public Map<String, Object> getComponentConfiguration() { 78 return null; 79 } 80 81 }
第四:bolt3的代码---PrintBolt.java
打印bolt
1 package cn.aeths.storm.helloworld.bolt; 2 3 import backtype.storm.topology.BasicOutputCollector; 4 import backtype.storm.topology.OutputFieldsDeclarer; 5 import backtype.storm.topology.base.BaseBasicBolt; 6 import backtype.storm.tuple.Fields; 7 import backtype.storm.tuple.Tuple; 8 9 @SuppressWarnings("serial") 10 public class PrintBolt extends BaseBasicBolt{ 11 12 public void execute(Tuple input, BasicOutputCollector collector) { 13 String mesg = input.getString(0); 14 if(mesg!=null) 15 System.out.println(mesg); 16 } 17 18 public void declareOutputFields(OutputFieldsDeclarer declarer) { 19 declarer.declare(new Fields("word")); 20 } 21 22 }
第五:topology的代码---WordCountTopology
将这些类组成一个Topology分别设置集群模式和本地模式的提交运行与回收
1 package cn.aeths.storm.helloworld; 2 3 import backtype.storm.Config; 4 import backtype.storm.LocalCluster; 5 import backtype.storm.StormSubmitter; 6 import backtype.storm.topology.TopologyBuilder; 7 import backtype.storm.tuple.Fields; 8 import backtype.storm.utils.Utils; 9 import cn.aeths.storm.helloworld.bolt.PrintBolt; 10 import cn.aeths.storm.helloworld.bolt.WordCountBolt; 11 import cn.aeths.storm.helloworld.bolt.WordNormalizerBolt; 12 import cn.aeths.storm.helloworld.spout.RandomSentenceSpout; 13 14 public class WordCountTopology { 15 private static TopologyBuilder builder = new TopologyBuilder(); 16 public static void main(String[] args){ 17 18 Config config = new Config(); 19 builder.setSpout("RandomSentence", new RandomSentenceSpout(),2); 20 builder.setBolt("WordNormalizer", new WordNormalizerBolt(),2).shuffleGrouping("RandomSentence"); 21 builder.setBolt("WordCount", new WordCountBolt(),2).fieldsGrouping("WordNormalizer",new Fields("word")); 22 builder.setBolt("Print", new PrintBolt(),1).shuffleGrouping("WordCount"); 23 24 config.setDebug(false); 25 26 if(args!=null && args.length>0){ 27 config.setNumWorkers(3); 28 try { 29 StormSubmitter.submitTopology(args[0], config, builder.createTopology()); 30 } catch (Exception e) { 31 e.printStackTrace(); 32 } 33 34 }else{ 35 config.setMaxTaskParallelism(1); 36 LocalCluster cluster = new LocalCluster(); 37 cluster.submitTopology("WordCount", config, builder.createTopology()); 38 Utils.sleep(10000); 39 cluster.killTopology("WorldCount"); 40 cluster.shutdown(); 41 } 42 43 } 44 45 46 }
第六:util的代码---MapSort.java
将map按照key排序之后,输出map的工具类
1 package cn.aeths.storm.helloworld.util; 2 3 import java.util.Collections; 4 import java.util.Comparator; 5 import java.util.HashMap; 6 import java.util.Iterator; 7 import java.util.LinkedHashMap; 8 import java.util.LinkedList; 9 import java.util.List; 10 import java.util.Map; 11 12 public class MapSort { 13 @SuppressWarnings({ "unchecked", "rawtypes" }) 14 public static Map<String, Integer> sortByValue(Map<String,Integer> map){ 15 if(map==null){ 16 return null; 17 } 18 List<Integer> list = new LinkedList(map.entrySet()); 19 Collections.sort(list,new Comparator(){ 20 public int compare(Object o1,Object o2){ 21 Comparable sort1 = (Comparable)((Map.Entry)o1).getValue(); 22 Comparable sort2 = (Comparable)((Map.Entry)o2).getValue(); 23 return sort2.compareTo(sort1); 24 } 25 }); 26 Map result = new LinkedHashMap(); 27 for(Iterator iterator = list.iterator();iterator.hasNext();){ 28 Map.Entry entry = (Map.Entry)iterator.next(); 29 result.put(entry.getKey(), entry.getValue()); 30 } 31 return result; 32 } 33 public static void main(String[] args){ 34 Map<String,Integer> map = new HashMap<String, Integer>(); 35 map.put("test", 3); 36 map.put("hcy", 1); 37 map.put("put",2); 38 map = sortByValue(map); 39 } 40 41 }
第七:pom.xml的代码
引用的还是storm-core-0.9.2
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 3 <modelVersion>4.0.0</modelVersion> 4 5 <groupId>cn.aeths</groupId> 6 <artifactId>storm-example</artifactId> 7 <version>0.0.1-SNAPSHOT</version> 8 <packaging>jar</packaging> 9 10 <name>storm-example</name> 11 <url>http://maven.apache.org</url> 12 13 <properties> 14 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 15 </properties> 16 17 <dependencies> 18 19 <dependency> 20 <groupId>junit</groupId> 21 <artifactId>junit</artifactId> 22 <version>3.8.1</version> 23 <scope>test</scope> 24 </dependency> 25 26 <dependency> 27 <groupId>org.apache.maven.plugins</groupId> 28 <artifactId>maven-resources-plugin</artifactId> 29 <version>2.4.3</version> 30 </dependency> 31 32 <dependency> 33 <groupId>org.apache.storm</groupId> 34 <artifactId>storm-core</artifactId> 35 <version>0.9.2-incubating</version> 36 <scope>provided</scope> 37 </dependency> 38 39 </dependencies> 40 41 <build> 42 <plugins> 43 44 <plugin> 45 <artifactId>maven-assembly-plugin</artifactId> 46 <version>2.4</version> 47 <configuration> 48 49 <descriptorRefs> 50 <descriptorRef>jar-with-dependencies</descriptorRef> 51 </descriptorRefs> 52 <archive> 53 <manifest> 54 <mainClass> 55 cn.aeths.storm.helloworld.WorldCountTopology 56 </mainClass> 57 </manifest> 58 </archive> 59 </configuration> 60 <executions> 61 <execution> 62 <id>make-assembly</id> 63 <phase>package</phase> 64 <goals> 65 <goal>single</goal> 66 </goals> 67 </execution> 68 </executions> 69 </plugin> 70 71 </plugins> 72 </build> 73 </project>
第八:工程的目录结构
第九:运行的效果
1 44419 [Thread-18-Print] INFO backtype.storm.daemon.executor - Preparing bolt Pr 2 int:(1) 3 44420 [Thread-18-Print] INFO backtype.storm.daemon.executor - Prepared bolt Pri 4 nt:(1) 5 44434 [Thread-19-worker-receiver-thread-0] INFO backtype.storm.messaging.loader 6 - Starting receive-thread: [stormId: WordCount-1-1464826598, port: 1027, thread 7 -id: 0 ] 8 The first8: [the.1] 9 The first8: [the.1],[cow:1] 10 The first8: [the.1],[cow:1],[jumped:1] 11 The first8: [the.1],[cow:1],[jumped:1],[over:1] 12 The first8: [the.2],[cow:1],[jumped:1],[over:1] 13 The first8: [the.2],[cow:1],[jumped:1],[over:1],[moon:1] 14 The first8: [the.2],[cow:1],[jumped:1],[over:1],[moon:1],[hello:1] 15 The first8: [the.2],[cow:1],[jumped:1],[over:1],[moon:1],[hello:1],[world:1] 16 The first8: [the.2],[cow:1],[jumped:1],[over:1],[moon:1],[hello:1],[world:1],[an 17 :1] 18 The first8: [the.2],[cow:1],[jumped:1],[over:1],[moon:1],[hello:1],[world:1],[an 19 :1] 20 The first8: [the.2],[cow:1],[jumped:1],[over:1],[moon:1],[hello:1],[world:1],[an 21 :1] 22 The first8: [the.2],[cow:1],[jumped:1],[over:1],[moon:1],[hello:1],[world:1],[an 23 :1] 24 The first8: [the.2],[cow:1],[jumped:1],[over:1],[moon:1],[hello:1],[world:1],[an 25 :1] 26 The first8: [the.3],[cow:1],[jumped:1],[over:1],[moon:1],[hello:1],[world:1],[an 27 :1] 28 The first8: [the.3],[cow:1],[jumped:1],[over:1],[moon:1],[hello:1],[world:1],[an 29 :1] 30 The first8: [the.3],[cow:1],[jumped:1],[over:1],[moon:1],[hello:1],[world:1],[an 31 :1] 32 The first8: [the.3],[cow:1],[jumped:1],[over:1],[moon:1],[hello:1],[world:1],[an 33 :1] 34 The first8: [the.3],[world:2],[cow:1],[jumped:1],[over:1],[moon:1],[hello:1],[an 35 :1] 36 52768 [main] ERROR org.apache.zookeeper.server.NIOServerCnxnFactory - Thread Thr 37 ead[main,5,main] died 38 backtype.storm.generated.NotAliveException: null 39 at backtype.storm.daemon.nimbus$check_storm_active_BANG_.invoke(nimbus.clj:744) 40 ~[storm-core-0.9.2-incubating.jar:0.9.2-incubating] 41 at backtype.storm.daemon.nimbus$fn__4173$exec_fn__1096__auto__$reify__4186.kill 42 TopologyWithOpts(nimbus.clj:968) ~[storm-core-0.9.2-incubating.jar:0.9.2-incubat 43 ing] 44 at backtype.storm.daemon.nimbus$fn__4173$exec_fn__1096__auto__$reify__4186.kill 45 Topology(nimbus.clj:965) ~[storm-core-0.9.2-incubating.jar:0.9.2-incubating] 46 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_74] 47 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_74] 48 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_7 49 4] 50 at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_74] 51 at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:93) ~[clojure-1.5 52 .1.jar:na] 53 at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:28) ~[clojure-1.5 54 .1.jar:na] 55 at backtype.storm.LocalCluster$_killTopology.invoke(LocalCluster.clj:51) ~[stor 56 m-core-0.9.2-incubating.jar:0.9.2-incubating] 57 at backtype.storm.LocalCluster.killTopology(Unknown Source) ~[storm-core-0.9.2- 58 incubating.jar:0.9.2-incubating] 59 at cn.aeths.storm.helloworld.WordCountTopology.main(WordCountTopology.java:39) 60 ~[classes/:na] 61 The first8: [the.3],[world:2],[cow:1],[jumped:1],[over:1],[moon:1],[hello:1],[an 62 :1] 63 The first8: [the.3],[world:2],[cow:1],[jumped:1],[over:1],[moon:1],[hello:1],[an 64 :1] 65 The first8: [the.3],[world:2],[cow:1],[jumped:1],[over:1],[moon:1],[hello:1],[an 66 :1] 67 The first8: [the.4],[world:2],[cow:1],[jumped:1],[over:1],[moon:1],[hello:1],[an 68 :1] 69 The first8: [the.4],[world:2],[cow:1],[jumped:1],[over:1],[moon:1],[hello:1],[an 70 :1] 71 The first8: [the.4],[world:2],[cow:1],[jumped:1],[over:1],[moon:1],[hello:1],[an 72 :1] 73 The first8: [the.4],[world:2],[big:2],[cow:1],[jumped:1],[over:1],[moon:1],[hell 74 o:1] 75 The first8: [the.4],[world:3],[big:2],[cow:1],[jumped:1],[over:1],[moon:1],[hell 76 o:1] 77 The first8: [the.5],[world:3],[big:2],[cow:1],[jumped:1],[over:1],[moon:1],[hell 78 o:1] 79 The first8: [the.5],[world:3],[big:2],[cow:2],[jumped:1],[over:1],[moon:1],[hell 80 o:1] 81 The first8: [the.5],[world:3],[big:2],[cow:2],[jumped:2],[over:1],[moon:1],[hell 82 o:1] 83 The first8: [the.5],[world:3],[big:2],[cow:2],[jumped:2],[over:2],[moon:1],[hell 84 o:1] 85 The first8: [the.6],[world:3],[big:2],[cow:2],[jumped:2],[over:2],[moon:1],[hell 86 o:1] 87 The first8: [the.6],[world:3],[big:2],[cow:2],[jumped:2],[over:2],[moon:2],[hell 88 o:1] 89 The first8: [the.6],[world:3],[big:2],[cow:2],[jumped:2],[over:2],[moon:2],[hell 90 o:1] 91 The first8: [the.6],[world:3],[big:2],[cow:2],[jumped:2],[over:2],[moon:2],[hell 92 o:1] 93 The first8: [the.6],[world:3],[big:2],[cow:2],[jumped:2],[over:2],[moon:2],[and: 94 2] 95 The first8: [the.6],[world:3],[big:2],[cow:2],[jumped:2],[over:2],[moon:2],[and: 96 2] 97 The first8: [the.6],[world:3],[big:2],[cow:2],[jumped:2],[over:2],[moon:2],[and: 98 2] 99 The first8: [the.6],[world:3],[big:2],[cow:2],[jumped:2],[over:2],[moon:2],[and: 100 2] 101 The first8: [the.6],[world:3],[big:2],[cow:2],[jumped:2],[over:2],[moon:2],[and: 102 2] 103 The first8: [the.6],[world:3],[big:2],[cow:2],[jumped:2],[over:2],[moon:2],[and: 104 2] 105 The first8: [the.6],[world:3],[and:3],[big:2],[cow:2],[jumped:2],[over:2],[moon: 106 2] 107 The first8: [the.6],[world:3],[and:3],[seven:3],[big:2],[cow:2],[jumped:2],[over 108 :2] 109 The first8: [the.6],[world:3],[and:3],[seven:3],[big:2],[cow:2],[jumped:2],[over 110 :2] 111 The first8: [the.6],[world:3],[and:3],[seven:3],[big:2],[cow:2],[jumped:2],[over 112 :2] 113 The first8: [the.6],[world:3],[and:3],[seven:3],[big:3],[cow:2],[jumped:2],[over 114 :2] 115 The first8: [the.6],[world:4],[and:3],[seven:3],[big:3],[cow:2],[jumped:2],[over 116 :2] 117 The first8: [the.6],[world:4],[and:3],[seven:3],[big:3],[four:3],[cow:2],[jumped 118 :2] 119 The first8: [the.6],[world:4],[and:3],[seven:3],[big:3],[four:3],[score:3],[cow: 120 2] 121 The first8: [the.6],[world:4],[and:4],[seven:3],[big:3],[four:3],[score:3],[cow: 122 2] 123 The first8: [the.6],[world:4],[and:4],[seven:4],[big:3],[four:3],[score:3],[cow: 124 2] 125 The first8: [the.6],[world:4],[and:4],[seven:4],[big:3],[four:3],[score:3],[year 126 s:3] 127 The first8: [the.6],[world:4],[and:4],[seven:4],[big:3],[four:3],[score:3],[year 128 s:3] 129 The first8: [the.6],[world:4],[and:4],[seven:4],[four:4],[big:3],[score:3],[year 130 s:3] 131 The first8: [the.6],[world:4],[and:4],[seven:4],[four:4],[score:4],[big:3],[year 132 s:3] 133 The first8: [the.6],[and:5],[world:4],[seven:4],[four:4],[score:4],[big:3],[year 134 s:3] 135 The first8: [the.6],[and:5],[seven:5],[world:4],[four:4],[score:4],[big:3],[year 136 s:3]
第十:出现的问题
首先是这个错误
可能是我没有把本地集群关闭,那几行没写,但是正常运行的9的结果也出现了这个问题。待续吧。
1 41030 [main-EventThread] INFO org.apache.curator.framework.state.ConnectionStat 2 eManager - State change: CONNECTED 3 41030 [ConnectionStateManager-0] WARN org.apache.curator.framework.state.Connec 4 tionStateManager - There are no ConnectionStateListeners registered. 5 41045 [main] INFO backtype.storm.daemon.supervisor - Starting supervisor with i 6 d ce0df93a-0061-4107-aab0-378bc2adcdac at host kongchung 7 41108 [main] WARN backtype.storm.daemon.nimbus - Topology submission exception. 8 (topology name='wordcount') #<InvalidTopologyException InvalidTopologyException 9 (msg:Component: [Print] subscribes from non-existent stream: [default] of compon 10 ent [WordCount])> 11 41124 [main] ERROR org.apache.zookeeper.server.NIOServerCnxnFactory - Thread Thr 12 ead[main,5,main] died 13 backtype.storm.generated.InvalidTopologyException: null 14 at backtype.storm.daemon.common$validate_structure_BANG_.invoke(common.clj:169) 15 ~[storm-core-0.9.2-incubating.jar:0.9.2-incubating] 16 at backtype.storm.daemon.common$system_topology_BANG_.invoke(common.clj:304) ~[ 17 storm-core-0.9.2-incubating.jar:0.9.2-incubating] 18 at backtype.storm.daemon.nimbus$fn__4173$exec_fn__1096__auto__$reify__4186.subm 19 itTopologyWithOpts(nimbus.clj:944) ~[storm-core-0.9.2-incubating.jar:0.9.2-incub 20 ating] 21 at backtype.storm.daemon.nimbus$fn__4173$exec_fn__1096__auto__$reify__4186.subm 22 itTopology(nimbus.clj:962) ~[storm-core-0.9.2-incubating.jar:0.9.2-incubating] 23 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_74] 24 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_74] 25 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_7 26 4] 27 at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_74] 28 at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:93) ~[clojure-1.5 29 .1.jar:na] 30 at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:28) ~[clojure-1.5 31 .1.jar:na] 32 at backtype.storm.testing$submit_local_topology.invoke(testing.clj:253) ~[storm 33 -core-0.9.2-incubating.jar:0.9.2-incubating] 34 at backtype.storm.LocalCluster$_submitTopology.invoke(LocalCluster.clj:38) ~[st 35 orm-core-0.9.2-incubating.jar:0.9.2-incubating] 36 at backtype.storm.LocalCluster.submitTopology(Unknown Source) ~[storm-core-0.9. 37 2-incubating.jar:0.9.2-incubating] 38 at cn.aeths.storm.helloworld.WorldCountTopology.main(WorldCountTopology.java:38 39 ) ~[classes/:na]
然后是这个错误
文献:http://bbs.csdn.net/topics/390721505
说是因为字段声明有问题果然是我的一个字段的声明没写是空的,添加之后能妥善运行了。
1 40681 [main] INFO backtype.storm.daemon.supervisor - Starting supervisor with i 2 d 42584273-a237-4472-a830-595633f81cb9 at host kongchung 3 40744 [main] WARN backtype.storm.daemon.nimbus - Topology submission exception. 4 (topology name='WordCount') #<InvalidTopologyException InvalidTopologyException 5 (msg:Component: [Print] subscribes from non-existent stream: [default] of compon 6 ent [WordCount])> 7 40744 [main] ERROR org.apache.zookeeper.server.NIOServerCnxnFactory - Thread Thr 8 ead[main,5,main] died 9 backtype.storm.generated.InvalidTopologyException: null
1 //字段声明 2 public void declareOutputFields(OutputFieldsDeclarer declarer) { 3 declarer.declare(new Fields("word")); 4 }
storm的javadoc很多的东西描述的不清楚,或者人觉得不用描述,现在就是学着用很多的类都没看懂怎么用。慢慢学吧。
2016-06-02 08:26:58