storm程序开发好之后,本地测试通过,需要到集群环境下测试,每次都得打包上传服务器,相当的麻烦,想成为一个优秀的程序员,必须学会偷懒,于是有了以下代码。
本地运行模式:
// 本地模式 LocalCluster local = new LocalCluster(); local.submitTopology(TOPOLOGY_NAME, conf, builder.createTopology());集群运行模式:
// 集群模式 try { StormSubmitter.submitTopology(TOPOLOGY_NAME, conf, builder.createTopology()); } catch (AlreadyAliveException e) { e.printStackTrace(); } catch (InvalidTopologyException e) { e.printStackTrace(); }idea直接提交到集群运行模式:
// idea提交任务,读取本地Storm-core配置文件,提交集群 try { // 读取本地storm-core包下的storm.yaml配置 Map stormConf = Utils.readStormConfig(); // 读取classpath下的配置文件 // Map stormConf = Utils.findAndReadConfigFile("storm.yaml"); stormConf.put(Config.NIMBUS_HOST, "111.111.111.111"); stormConf.put(Config.WORKER_CHILDOPTS, "-Xmx8192m"); stormConf.putAll(conf); System.out.println(stormConf); // 提交集群运行的jar String inputJar = "D:\\workspace-bonc\\GGSNStorm\\target\\GGSNStorm-1.0-SNAPSHOT.jar"; // 使用StormSubmitter提交jar包 String uploadedJarLocation = StormSubmitter.submitJar(stormConf, inputJar); String jsonConf = JSONValue.toJSONString(stormConf); // 这种方式也可以,跟下面两句代码效果一致 // Nimbus.Client client = NimbusClient.getConfiguredClient(stormConf).getClient(); // client.submitTopology(TOPOLOGY_NAME, uploadedJarLocation, jsonConf, builder.createTopology()); NimbusClient nimbus = new NimbusClient(stormConf, "111.111.111.111", 6627); nimbus.getClient().submitTopology(TOPOLOGY_NAME, uploadedJarLocation, jsonConf, builder.createTopology()); } catch (Exception e) { e.printStackTrace(); }
亲测没问题!
分享:
下一篇KeeperErrorCode = NoNode for /brokers/topics/test_topic/partitions
崇尚极简,热爱技术,喜欢唱歌,热衷旅行,爱好电子产品的一介码农。
联系QQ:58742094
联系电话:
工作邮箱:
当你的才华还撑不起你的野心的时候,你就应该静下心来学习,永不止步!
人生之旅历途甚长,所争决不在一年半月,万不可因此着急失望,招精神之萎葸。
Copyright 2015- 芒果酷(mangocool.com) All rights reserved. 湘ICP备14019394号
免责声明:本网站部分文章转载其他媒体,意在为公众提供免费服务。如有信息侵犯了您的权益,可与本网站联系,本网站将尽快予以撤除。