本系列属个人原创,转载请注明!
原文地址:http://blog.youkuaiyun.com/xeseo/article/details/18219183
本系列源码地址: https://github.com/EdisonXu/storm-samples
根据前文介绍,我们知道,storm的任务是包装在topology类中,由nimbus提交分配到整个cluster。
Topology有两种大类提交部署方式:
- 提交到本地模式,一般用于调试。该模式下由于是起在同一个JVM进程下,所以不要让其负载太高。
- 提交到集群模式。
提交到本地模式
这个非常的简单。
1. 编写代码
public class LocalRunningTopology extends ExclaimBasicTopo {
public static void main(String[] args) throws Exception {
LocalRunningTopology topo = new LocalRunningTopology();
Config conf = new Config();
conf.setDebug(true);
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("test", conf, topo.buildTopology());
Utils.sleep(100000);
cluster.killTopology("test");
cluster.shutdown();
}
}
2. 直接就可以在IDE里面运行,也可以提交到nimbus上,用nimbus进行本地运行:./storm jar storm-samples.jar com.edi.storm.topos.LocalRunningTopology
提交到集群
1. 编写代码
public class ClusterRunningTopology extends ExclaimBasicTopo {
public static void main(String[] args) throws Exception {
String topoName = "test";
ClusterRunningTopology topo = new ClusterRunningTopology();
Config conf = new Config();
conf.setDebug(true);
conf.setNumWorkers(3);
StormSubmitter.submitTopology(topoName, conf, topo.buildTopology());
}
}
2. 编译jar包
因为我是Maven项目,所以直接
mvn clean install 生成jar
3. 上传至