資源簡(jiǎn)介
K天熟悉Apache Storm (三)的示例代碼,實(shí)時(shí)單詞計(jì)數(shù)應(yīng)用場(chǎng)景

代碼片段和文件信息
package?wc.redis;
import?wc.redis.bolt.CountBolt;
import?wc.redis.bolt.SplitBolt;
import?wc.redis.spout.WCSpout;
import?backtype.storm.Config;
import?backtype.storm.StormSubmitter;
import?backtype.storm.generated.AlreadyAliveException;
import?backtype.storm.generated.InvalidTopologyException;
import?backtype.storm.topology.TopologyBuilder;
import?backtype.storm.tuple.Fields;
/**
?*?功能:
?*?使用java程序定時(shí)向Redis數(shù)據(jù)庫(kù)A中插入數(shù)據(jù)
?*?使用Spout定時(shí)讀取Redis中的數(shù)據(jù)
?*?使用SplitBolt把數(shù)據(jù)分為單詞
?*?使用CountBolt對(duì)單詞計(jì)數(shù),同時(shí)定時(shí)向Redis數(shù)據(jù)庫(kù)B中插入單詞計(jì)數(shù)
?*?使用java程序定時(shí)讀取Redis數(shù)據(jù)庫(kù)B中的數(shù)據(jù),進(jìn)行打印
?*?
?*?@author?fansy
?*?@date?2015/3/25?23:31
?*/
public?class?WCTopology?{
/**
?*?@param?args
?*?@throws?InvalidTopologyException?
?*?@throws?AlreadyAliveException?
?*/
public?static?void?main(String[]?args)?throws?AlreadyAliveException?InvalidTopologyException?{
if(args.length!=7){
System.out.println(“\nwc.redis.WCTopology??“?+
“????“+
“?“);
}
?//Topology?definition
TopologyBuilder?builder?=?new?TopologyBuilder();
builder.setSpout(“wc-spout“new?WCSpout()Integer.parseInt(args[2]));
builder.setBolt(“split-bolt“?new?SplitBolt()Integer.parseInt(args[3]))
.shuffleGrouping(“wc-spout“);
builder.setBolt(“count-bolt“?new?CountBolt()Integer.parseInt(args[4]))
.fieldsGrouping(“split-bolt“?new?Fields(“word“));
//?定義Configuration
Config?conf?=?new?Config();
conf.put(“storeFrequent“?Long.parseLong(args[0]));
conf.put(“slow_fast“?args[5]);
conf.put(“printWC“?args[6]);
conf.setNumWorkers(Integer.parseInt(args[1]));
//?提交任務(wù)
StormSubmitter.submitTopology(“wc-redis-14“?confbuilder.?createTopology());
}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????767??2015-03-24?16:02??StormTest1.4\.classpath
?????文件????????388??2015-03-26?21:57??StormTest1.4\.project
?????文件????????629??2015-03-19?00:21??StormTest1.4\.settings\org.eclipse.jdt.core.prefs
?????文件???????4449??2015-03-26?21:58??StormTest1.4\bin\wc\redis\bolt\CountBolt.class
?????文件???????3188??2015-03-26?21:57??StormTest1.4\bin\wc\redis\bolt\SplitBolt.class
?????文件???????2929??2015-03-26?21:58??StormTest1.4\bin\wc\redis\insert_get\RandomRedisInsert.class
?????文件???????3279??2015-03-26?21:58??StormTest1.4\bin\wc\redis\insert_get\RedisGetTest.class
?????文件???????3305??2015-03-26?21:58??StormTest1.4\bin\wc\redis\insert_get\RedisGetTest2.class
?????文件???????4145??2015-03-26?22:12??StormTest1.4\bin\wc\redis\spout\WCSpout.class
?????文件???????2078??2015-03-26?21:58??StormTest1.4\bin\wc\redis\util\RedisUtils.class
?????文件???????2588??2015-03-26?22:15??StormTest1.4\bin\wc\redis\WCTopology.class
?????文件???????2862??2015-03-26?17:57??StormTest1.4\src\wc\redis\bolt\CountBolt.java
?????文件???????2154??2015-03-26?17:21??StormTest1.4\src\wc\redis\bolt\SplitBolt.java
?????文件???????2108??2015-03-26?17:11??StormTest1.4\src\wc\redis\insert_get\RandomRedisInsert.java
?????文件???????1606??2015-03-25?23:23??StormTest1.4\src\wc\redis\insert_get\RedisGetTest.java
?????文件???????1707??2015-03-26?00:57??StormTest1.4\src\wc\redis\insert_get\RedisGetTest2.java
?????文件???????2797??2015-03-26?22:12??StormTest1.4\src\wc\redis\spout\WCSpout.java
?????文件???????1152??2015-03-26?21:58??StormTest1.4\src\wc\redis\util\RedisUtils.java
?????文件???????1862??2015-03-26?22:15??StormTest1.4\src\wc\redis\WCTopology.java
?????目錄??????????0??2015-03-26?21:57??StormTest1.4\bin\wc\redis\bolt
?????目錄??????????0??2015-03-26?21:57??StormTest1.4\bin\wc\redis\insert_get
?????目錄??????????0??2015-03-26?21:57??StormTest1.4\bin\wc\redis\spout
?????目錄??????????0??2015-03-26?21:57??StormTest1.4\bin\wc\redis\util
?????目錄??????????0??2015-03-26?21:57??StormTest1.4\src\wc\redis\bolt
?????目錄??????????0??2015-03-26?21:57??StormTest1.4\src\wc\redis\insert_get
?????目錄??????????0??2015-03-26?21:57??StormTest1.4\src\wc\redis\spout
?????目錄??????????0??2015-03-26?21:57??StormTest1.4\src\wc\redis\util
?????目錄??????????0??2015-03-26?21:57??StormTest1.4\bin\wc\redis
?????目錄??????????0??2015-03-26?21:57??StormTest1.4\src\wc\redis
?????目錄??????????0??2015-03-26?21:57??StormTest1.4\bin\wc
............此處省略10個(gè)文件信息
評(píng)論
共有 條評(píng)論