开发环境定义:
Storm有两种操作模式:本地模式和远程模式。本地模式允许在本机开发测试Storm topologies,远程模式允许你提交topologies到Storm集群上执行。
开发环境则将所有的功能包括在内,以使你能在本机开发测试,也能提交topologies包到远程集群上运行,同时可以kill掉远程上运行的topology。
步骤:
1. 下载一个Storm release,解压缩到任意目录,将bin/目录放到PATH环境变量中。
2. 为了能够开启和关闭远程集群上的topologies,需要
将远程集群上master的主机地址放到~/.storm/storm.yaml文件中,来指明客户端通信的集群是哪个。配置如下:
nimbus.seeds: ["123.45.678.890"]
3. 开发环境中建议使用maven添加storm依赖:
org.apache.storm
storm-core
1.1.1
provided
Here's an example of a pom.xml for a Storm project.
1) 定义topology (在Java中使用 TopologyBuilder 来定义)
TopologyBuilder builder = newTopologyBuilder();
builder.setSpout("1", new TestWordSpout(true), 5);
builder.setSpout("2", new TestWordSpout(true), 3);
builder.setBolt("3", new TestWordCounter(), 3)
.fieldsGrouping("1", new Fields("word"))
.fieldsGrouping("2", new Fields("word"));
builder.setBolt("4", newTestGlobalCount())
.globalGrouping("1");
StormTopology topology= builder.createTopology();
2) 使用 StormSubmitter 提交topology到集群上。
Config conf = newConfig();
conf.setNumWorkers(20);
conf.setMaxSpoutPending(5000);
StormSubmitter.submitTopology("mytopology", conf, topology);
3) 将你的代码和其依赖打包成jar包(除了Storm相关的jar包 -- 这些jar包会加到worker节点的类路径上).
如果你使用Maven来构建项目的话,Maven Assembly Plugin 可以帮你做这项工作,只需要你添加如下配置到pom.xml中:
maven-assembly-plugin
jar-with-dependencies
com.path.to.main.Class
4) 使用 storm客户端工具将topology提交到集群, 指定你jar包所在路径,运行类的名称以及运行参数:
storm jar path/to/allmycode.jar org.me.MyTopology arg1 arg2 arg3
storm jar 将提交jar到集群上并配置 StormSubmitter 类来和正确的集群会话。在这个例子中, 上传完storm jar 后 org.me.MyTopology 中带有 "arg1", "arg2", and "arg3"参数的main方法将会执行。
一般配置项:
所有配置项列表可以在这找到。 那些带 "TOPOLOGY" 前缀的可以被重新设置,常用的设置项如下:
1.Config.TOPOLOGY_WORKERS: worker的进程数.
2. Config.TOPOLOGY_ACKER_EXECUTORS:ACKER的数量,不设置该项,或者设置该项为null,Storm将设置ACKER数为worker数. 如果设置该项为0,则Storm会在tuple从spout中出来时,立即 ack,这将大大地限制可靠性。
3. Config.TOPOLOGY_MAX_SPOUT_PENDING: 单个spout任务上单次能添加的最大tuple数(pending means the tuple has not been acked or failed yet). 强烈建议加上以防队列溢出.
4. Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS: 被认为执行失败的最大时间。默认30秒,这对大多数topology来说是足够运行的。 Guaranteeing message processing for more information on how Storm's reliability model works.
5. Config.TOPOLOGY_SERIALIZATIONS: You can register more serializers to Storm using this config so that you can use custom types within tuples.
Killing a topology
只需要运行:
storm kill {stormname}
Storm 将不会立即杀死 topology进程. 而是先使所有的spout失效,然后等待TOPOLOGY_MESSAGE_TIMEOUT_SECS 秒后销毁所有的worker进程.
Updating a running topology
现在只能先kill再重新提交。计划将来能实现 storm swap 命令来 that swaps a running topology with a new one, ensuring minimal downtime and no chance of both topologies processing tuples at the same time.
Monitoring topologies
Storm UI和集群上的worker的日志。