如何使用 IDE 在风暴生产群集中提交拓扑

2022-09-02 23:39:35

在使用IDE将拓扑提交到生产集群时,我遇到了一个问题,而如果我使用命令在命令行中执行,则同样的事情会像天堂一样运行。我从githublink中看到了同样的例子。Must submit topologies using the 'storm' client script so that StormSubmitter knows which jar to uploadstorm jar

为了提交拓扑,我正在使用这些行集

conf.put(Config.NIMBUS_HOST, NIMBUS_NODE);
conf.put(Config.NIMBUS_THRIFT_PORT,6627);
conf.put(Config.STORM_ZOOKEEPER_PORT,2181);
conf.put(Config.STORM_ZOOKEEPER_SERVERS,ZOOKEEPER_ID);
conf.setNumWorkers(20);
conf.setMaxSpoutPending(5000);
StormSubmitter submitter = new StormSubmitter();
submitter.submitTopology("test", conf, builder.createTopology());

请建议我,如果这是正确的运行方法?


答案 1

很好地找到了解决方案。当我们运行“storm jar”时,它会在提交的jar中触发storm.jar的属性标志。因此,如果我们想以编程方式提交一个jar,那么只需以这种方式设置标志即可

System.setProperty("storm.jar", <path-to-jar>);

例如:

System.setProperty("storm.jar", "/Users/programming/apache-storm-1.0.1/lib/storm-core-1.0.1.jar");
StormSubmitter.submitTopology("myTopology", config, builder.createTopology());

答案 2

要将拓扑提交到远程 Storm 集群,您需要将该 jar 上传到 nimbus 计算机,然后使用 NimbusClient 将该 jar 提交到 Cluster。
你可以这样做:

Map storm_conf = Utils.readStormConfig();
storm_conf.put("nimbus.host", "<Nimbus Machine IP>");
Client client = NimbusClient.getConfiguredClient(storm_conf)
                                .getClient();
String inputJar = "C:\\workspace\\TestStormRunner\\target\\TestStormRunner-0.0.1-SNAPSHOT-jar-with-dependencies.jar";
NimbusClient nimbus = new NimbusClient(storm_conf, "<Nimbus Machine IP>",
                                <Nimbus Machine Port>);
 // upload topology jar to Cluster using StormSubmitter
String uploadedJarLocation = StormSubmitter.submitJar(storm_conf,
                                inputJar);

String jsonConf = JSONValue.toJSONString(storm_conf);
nimbus.getClient().submitTopology("testtopology",
                      <uploadedJarLocation>, jsonConf, builder.createTopology());

以下是工作示例:将拓扑提交到远程风暴群集


推荐