storm-example本地模式
1,到项目根目录下执行下面命令在本地模式下执行拓扑
mvn compile exec:java -Dexec.classpathScope=compile
-
Dexec.mainClass=com.learningstorm.storm_example.
LearningStormTopology
也可以在STS里运行:
结果如下:
9698 [Thread-18-LearningStormBolt] INFO backtype.storm.daemon.executor - Processing received message source: LearningStormSpout:6, stream: default, id: {}, [youtube]
Name of input site is : youtube
9698 [Thread-18-LearningStormBolt] INFO backtype.storm.daemon.executor - Processing received message source: LearningStormSpout:6, stream: default, id: {}, [youtube]
Name of input site is : youtube
9698 [Thread-18-LearningStormBolt] INFO backtype.storm.daemon.executor - Processing received message source: LearningStormSpout:6, stream: default, id: {}, [linkedin]
Name of input site is : linkedin
9698 [Thread-18-LearningStormBolt] INFO backtype.storm.daemon.executor - Processing received message source: LearningStormSpout:6, stream: default, id: {}, [google]
Name of input site is : google
9698 [Thread-18-LearningStormBolt] INFO backtype.storm.daemon.executor - Processing received message source: LearningStormSpout:6, stream: default, id: {}, [youtube]
Name of input site is : youtube
9698 [Thread-18-LearningStormBolt] INFO backtype.storm.daemon.executor - Processing received message source: LearningStormSpout:6, stream: default, id: {}, [google]
Name of input site is : google
9698 [Thread-18-LearningStormBolt] INFO backtype.storm.daemon.executor - Processing received message source: LearningStormSpout:6, stream: default, id: {}, [youtube]
Name of input site is : youtube
9698 [Thread-18-LearningStormBolt] INFO backtype.storm.daemon.executor - Processing received message source: LearningStormSpout:6, stream: default, id: {}, [facebook]
Name of input site is : facebook
9698 [Thread-18-LearningStormBolt] INFO backtype.storm.daemon.executor - Processing received message source: LearningStormSpout:6, stream: default, id: {}, [youtube]
Name of input site is : youtube
9698 [Thread-18-LearningStormBolt] INFO backtype.storm.daemon.executor - Processing received message source: LearningStormSpout:6, stream: default, id: {}, [linkedin]
Name of input site is : linkedin
9698 [Thread-18-LearningStormBolt] INFO backtype.storm.daemon.executor - Processing received message source: LearningStormSpout:6, stream: default, id: {}, [youtube]
Name of input site is : youtube
9698 [Thread-18-LearningStormBolt] INFO backtype.storm.daemon.executor - Processing received message source: LearningStormSpout:6, stream: default, id: {}, [youtube]
Name of input site
单节点运行storm-example
1,下载解压storm并配置STORM_HOME环境变量
2,vi storm.yaml
storm.zookeeper.servers:
- "127.0.0.1"
storm.zookeeper.port: 2181
nimbus.host: "127.0.0.1"
storm.local.dir: "/tmp/storm-data"
java.library.path: "/usr/local/lib"
storm.messaging.transport: backtype.storm.messaging.netty.Context
supervisor.slots.ports:
- 6700
- 6701
- 6702
- 6703
3,启动storm
先启动zookeeper
bin/zkServer.sh start &
bin/storm nimbus &
bin/storm supervisor &
单节点拓扑源代码
public class LearningStormSingleNodeTopology {
public static void main(String[] args) {
TopologyBuilder builder = new TopologyBuilder();
// set the spout class
builder.setSpout("LearningStormSpout",
new LearningStormSpout(), 4);
// set the bolt class
builder.setBolt("LearningStormBolt",
new LearningStormBolt(), 2)
.shuffleGrouping("LearningStormSpout");
Config conf = new Config();
conf.setNumWorkers(3);
try {
// This statement submit the topology on remote
cluster.
// args[0] = name of topology
StormSubmitter.submitTopology(args[0], conf,
builder.createTopology());
}catch(AlreadyAliveException alreadyAliveException) {
System.out.println(alreadyAliveException);
} catch
(InvalidTopologyException invalidTopologyException) {
System.out.println(invalidTopologyException);
}
}
}
4,项目根目录下编译maven项目
mvn clean install
5,向集群部署拓扑
基本语法:
bin/storm jar jarName.jar [TopologyMainClass] [Args]
向集群发布本例子拓扑
bin/storm jar $PROJECT_HOME/target/storm-example-0.0.1-SNAPSHOT-
jar-with-dependencies.jar com.learningstorm.storm_example.
LearningStormSingleNodeTopology LearningStormSingleNodeTopology
通过jps看到有两个worker进程
6,让一个拓扑休眠(spout停止发消息)
bin/storm deactivate topologyName
7,激活一个拓扑
bin/storm activate topologyName
本例:
bin/storm activate LearningStormSingleNodeTopology
8,杀死拓扑
bin/storm kill LearningStormSingleNodeTopology