storm-example笔记

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值